How to setup a pipenv Python 3.6 project if OS Python version is 3.5?

删除回忆录丶 提交于 2019-12-02 17:30:36

Either manually write the version you need in your Pipfile:

[requires]
python_version = "3.6"

Or install it on your system. But I guess you will need the version to be installed if you plan to actually run pipenv install.

I would suggest to use pyenv: https://github.com/pyenv/pyenv.

Follow the installation instructions, then installing Python 3.6 is just a matter of

pyenv install 3.6.3

Then you can set the order of preference with

pyenv global system 3.6.3

Besides, if pyenv is available, pipenv will automatically use it to install the required version. From pipenv README:

Automatically install required Pythons, if pyenv is available.

Install python 3.6 reference

Ubuntu 14.04 and 16.04 If you are using Ubuntu 14.04 or 16.04, you can use Felix Krull's deadsnakes PPA at https://launchpad.net/~deadsnakes/+archive/ubuntu/ppa:

sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install python3.6

Alternatively, you can use J Fernyhough's PPA at https://launchpad.net/~jonathonf/+archive/ubuntu/python-3.6:

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

If you are using Ubuntu 16.10 or 17.04, then Python 3.6 is in the universe repository, so you can just run:

sudo apt-get update
sudo apt-get install python3.6

Then create specific version python env

virtualenv -p python3.6 python36venv

On MacOS, I have also used pyenv to manage python versions, similar to @pawamoy's suggestion.

After installation I executed pipenv shell with the --python option pointing to the directory of the specific pyenv version. This will automatically generate a Pipfile with python_version = "3.6".

⇒  pipenv --python /Users/<Your User>/.pyenv/versions/3.6.3/bin/python3.6 shell

Install 'pyenv' package by using brew install pyenv (if you don't have it).

Install python 3.6 using pyenv install 3.6

Export new installed python version to PATH

export PATH=${PYENV_PYTHON_VERSIONS_HOME}/3.6/bin

Now in 'Piplock' specify the same version.

[requires] python_version = "3.6"

Finally, run pipenv install --dev.

I don't think you can do a virtualenv of a Python version you don't have. What you can do is one of these options:


  • If you want to test your code in several versions of Python, the right way to go is Tox.
  • If you want multiples python installations available in your system, I recommend you asdf for Python.
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!