Cannot make Python 3.7 work in Ubuntu 18.04

Viewed 3382

I am learning Python and Django in Ubuntu 18.04 where both Python 3.6.7 and 3.7.2 is installed. Whenever Pyhon3 command is given its showing the prompt of 3.7, but when I use pipenv to create a virtual environment for a project it's still using /usr/bin/python3(Python3.6.7) and not of Python3.7.2. Even Python3.7.2 has been configured as default with highest priority of 2 by using the command:

sudo update-alternatives --install /usr/binpython3 python3 /usr/bin     /python3.6 1

sudo update-alternatives --install /usr/binpython3 python3 /usr/bin     /python3.7 2
sudo update-alternatives --configure python3

and the above command shows the Python3.7 as the default by a "*" symbol, but still pipenv uses Python3.6.7. I want pipenv to use only Python3.7 and not 3.6. Don't know what to do. Please help.

2 Answers

To find out the python location the system is running you can do

which python

Additionally, the issue may be pipenv specific instead of system.

Specify your target Python version in your Pipfile’s [requires] section. Ideally, you should only have one target Python version, as this is a deployment tool. General Recommendations & Version Control¶

This is more likely what you are looking for Set python version when creating virtualenv using pipenv


Some unwanted advice

My first recommendation is to ditch python 3.6 and stick to python 3.7. My second recommendation is to stop worrying about python versions. When you are learning, it doesn't matter which version you are using (I'm talking specifically between minor version numbers - 3.5/3.6/3.7 or anything above 3.3 - later on you'll learn the difference between version numbers). Here you can read the release notes for python 3.7

Since you just started to learn, your focus should be to understand the basics. You will get distracted switching between python 3.6 and python 3.7. And it will take longer.

However, you are learning the little details here and there, which is good, in a way. You need to ask yourself which is your priority.

Finally found a perfect solution to my problem.Its "pyenv".Have installed pyenv in ubuntu.Sorry thers no pyenv for windows. Its available only for Mac and Linux. I can install as many versions of Linux I like and use any of them per project basis.

All my confusions and problems are gone now.Very satisfied with the "pyenv" solution.

Related