无法安装pipenv python版本

2024-06-02 06:08:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试运行命令

pipenv install python==3.7.9

并得到下面的错误。当我跑的时候

which python

它显示“/Users/Micky/opt/anaconda3/bin/python”,版本为3.7.9

谁能告诉我怎么做

Micky-MBP:sportanalitica Micky$ pipenv install python==3.7.9
Installing python==3.7.9...
Error:  An error occurred while installing python==3.7.9!
Error text: 
ERROR: Could not find a version that satisfies the requirement python==3.7.9
ERROR: No matching distribution found for python==3.7.9

✘ Installation Failed 

Tags: install命令版本whichbinpipenv错误error
2条回答

Pipenv不用于安装Python版本。单独安装Python,然后使用Pipenv创建和管理虚拟环境,使用pipenv install <package>安装Python软件包

我认为您要做的是创建一个使用Python 3.7.9版本的虚拟环境。为此,指定Python版本的正确方法是将其作为 python=</path/to/python>选项传递。例如,对于^{}

~$ pipenv shell  help
Usage: pipenv shell [OPTIONS] [SHELL_ARGS]...

  Spawns a shell within the virtualenv.

Options:
  ...
   python TEXT       Specify which version of Python virtualenv should use.

相同的选项可用于pipenv install。因此,如果您有“python3指向/Users/Micky/opt/anaconda3/bin/python”:

~$ pipenv shell  python=/Users/Micky/opt/anaconda3/bin/python

请注意,只有在创建虚拟环境时,才必须传递 python选项。一旦它被创建,它将在PIP文件中“记住”它以使用该版本

temp$ pipenv shell  python=/usr/local/opt/python@3.7/bin/python3
...
✔ Successfully created virtual environment! 
...
Creating a Pipfile for this project...
Launching subshell in virtual environment...
...

(temp) temp$ python -V
Python 3.7.9

一旦创建了虚拟环境,就可以使用pipenv install <package>安装Python包(而不是Python本身):

(temp) temp$ pipenv install somepackage
(temp) temp$ pipenv install somepackage==1.0.0

我建议阅读Basic Usage of Pipenv docs

据我所见,我理解您希望在您的Pipenv中使用特定版本的Python。看起来您传递参数的方式是错误的。您传递的参数更多的是用于包,而不是Python版本

  • 要了解有关如何指定Python版本的更多信息,请参阅 here$ pipenv install python 3.7.9
  • 要指定Python二进制文件的完整路径,可以 请参阅here$ pipenv install python /Users/Micky/opt/anaconda3/bin/python
  • 最后,你可以使用一个技巧,就是pipenv install。一旦您有了一个PIP文件,就修改Python版本。然后使用pipenv rm删除安装。下一次pipenv install是第二次,它应该采用您先前修改的PIP文件中指定的版本

相关问题 更多 >