我的 Ubuntu 16.04.03 安装了 Python 3.5.2。当我的系统没有 python 3.6 时,如何设置 pipenv 以使用 Python 3.6?
$ pipenv --python 3.6
Warning: Python 3.6 was not found on your system…
You can specify specific versions of Python with:
$ pipenv --python path/to/python
在 Pipfile 中手动编写所需的版本:
[requires]
python_version = "3.6"
或者将其安装在您的系统上。但我想如果您打算实际运行,您将需要安装该版本pipenv install
。
我建议使用pyenv
:https ://github.com/pyenv/pyenv 。
按照安装说明,然后安装 Python 3.6 只是一个问题
pyenv install 3.6.3
然后你可以设置优先顺序
pyenv global system 3.6.3
此外,如果pyenv
可用,pipenv
将自动使用它来安装所需的版本。从pipenv
自述文件:
如果 pyenv 可用,则自动安装所需的 Python。
在 MacOS 上,我也使用pyenv来管理 python 版本,类似于@pawamoy 的建议。
安装后,我使用指向特定版本目录pipenv shell
的选项执行。这将自动生成一个with 。--python
pyenv
Pipfile
python_version = "3.6"
⇒ pipenv --python /Users/<Your User>/.pyenv/versions/3.6.3/bin/python3.6 shell
使用安装 'pyenv' 包brew install pyenv
(如果你没有的话)。
使用安装 python 3.6pyenv install 3.6
将新安装的 python 版本导出到 PATH
export PATH=${PYENV_PYTHON_VERSIONS_HOME}/3.6/bin
现在在“Piplock”中指定相同的版本。
[requires]
python_version = "3.6"
最后,运行pipenv install --dev
。
安装 python 3.6参考
Ubuntu 14.04 和 16.04 如果您使用的是 Ubuntu 14.04 或 16.04,您可以在https://launchpad.net/~deadsnakes/+archive/ubuntu/ppa使用 Felix Krull 的 deadsnakes PPA :
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install python3.6
或者,您可以在https://launchpad.net/~jonathonf/+archive/ubuntu/python-3.6使用 J Fernyhough 的 PPA :
sudo add-apt-repository ppa:jonathonf/python-3.6
sudo apt-get update
sudo apt-get install python3.6
Ubuntu 16.10 and 17.04
如果您使用的是 Ubuntu 16.10 或 17.04,那么 Python 3.6 位于 Universe 存储库中,因此您只需运行:
sudo apt-get update
sudo apt-get install python3.6
然后创建特定版本的python env
virtualenv -p python3.6 python36venv
在 MacOS(最新版本BigSur
和Monterey
)上,从下载 python 版本pyenv
会在构建时引发一些错误。所以我建议从官方网站简单地下载那个版本的python安装程序(在你的情况下是3.6)。然后使用命令
pipenv install --python 3.6
PS:不使用命令行的罕见时刻之一可以为您节省一些时间和挫败感。