70

My Ubuntu 16.04.03 is installed with Python 3.5.2. How do I setup pipenv to use Python 3.6 when my system does not have 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
Sun Bear
  • 7,594
  • 11
  • 56
  • 102

6 Answers6

90

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.

pawamoy
  • 3,382
  • 1
  • 26
  • 44
  • 4
    I selected this answer because `pyenv` allowed me to install various python versions w/o affecting or conflicting with the OS Python version. Thanks. – Sun Bear Apr 13 '18 at 23:40
  • 2
    Why is `pyenv` not installed together with `pipenv` ? – asmaier Jul 16 '18 at 12:14
  • Because the choice to use pyenv is left to the user :) And using pyenv (which is a bash script) requires the user to load it in the current shell (from .bashrc for example), and pipenv does not want to do it for you I guess. – pawamoy Jul 16 '18 at 12:19
  • 1
    I have 3.6.5 and 3.6.6 installed, when I specified 3.6.6 in the pipfile pipenv complained that I need 3.6.5. It did not automatically switch. – Harry Moreno Oct 01 '18 at 21:06
  • 1
    @parsecer make sure to follow the latest installation instruction at https://github.com/pyenv/pyenv – pawamoy Nov 21 '19 at 21:35
  • `Automatically install required Pythons, if pyenv is available.` - can you clarify? I ran `pipenv --python 3.10` and got "Warning: Python 3.10 was not found on your system…" so that doesn't seem to automatically installed a python version (I do have pyenv installed) – Augustine Calvino Nov 11 '21 at 07:32
  • This is what pipenv's README advertises. If it does not work, you definitely should open an issue on their issue tracker. – pawamoy Nov 12 '21 at 16:28
13

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
andrei1111
  • 454
  • 4
  • 6
10

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.

Adnan Murtaza
  • 127
  • 1
  • 5
  • where to write export PATH=${PYENV_PYTHON_VERSIONS_HOME}/3.6/bin and where to find piplock ? Please – Erika Dec 08 '22 at 21:52
5

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
Roushan
  • 4,074
  • 3
  • 21
  • 38
2

On MacOS (latest version BigSur and Monterey), downloading a version of python from pyenv throws some error while building. So I would suggest to simply download the python installer of that version (3.6 in your case) from the official site. Then use the command

pipenv install --python 3.6

PS: One of the rare moments where not using command line can save you a bit of time and frustration.

Amiay Narayan
  • 461
  • 9
  • 8
-1

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.