无法安装 pipenv python 版本

时间:2020-12-29 05:31:38

标签: python pipenv

我正在尝试运行命令

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 

2 个答案:

答案 0 :(得分:0)

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

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

~$ 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 选项。创建后,它会在 Pipfile 中“记住”它以使用该版本。

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

答案 1 :(得分:0)

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

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