3

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.

Sandip Nath
  • 622
  • 2
  • 8
  • 18
  • Check you PATH. It is, because python finds 3.6 first while looking for **python** executable. If you will change the order or rename them as Python3. 6 or Python3. 7, it is ok. But it is like putting yourself in a risk. As you need to take of rollbacking the changes. As most of the applications depends on Python. – hygull Jan 10 '19 at 16:41
  • Please explain. I gave the command echo $PATH which displays the contents of /etc/environment file. No mention of either of the linux are there. Feeling helpless. – Sandip Nath Jan 10 '19 at 16:44
  • Check under **/usr/** if there are python executables. It depends how you have installed it. Once you will find rename or remove uncessary things. – hygull Jan 10 '19 at 16:46
  • Yes under /usr/bin/ there are both Python3.6 and 3.7. – Sandip Nath Jan 10 '19 at 16:49
  • Check this https://askubuntu.com/questions/262063/how-to-find-python-installation-directory-on-ubuntu to check python executables location in Ubuntu. – hygull Jan 10 '19 at 16:49
  • Ok, got it. So now you check the name of executables. If you want to use both. Change their name (I don't want you to do this). It's risky. Or just change the name of your Python 3.6 executable to any other name and leave Pytjon3. 7 executable as it is. – hygull Jan 10 '19 at 16:51
  • Close all terminals, open new one and try again. It will work. – hygull Jan 10 '19 at 16:53
  • Doesn't solved my problem. I am annoyed with the pipenv using python3.6 when python3.7 has been set as default properly and the command output shows it. If python3 command is given in the terminal its opening the python3.7 as my wish. Only pipenv is not working properly. – Sandip Nath Jan 10 '19 at 16:59
  • I would recommend using `pyenv` – OneCricketeer Jan 10 '19 at 18:10

2 Answers2

0

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.

teichopsia
  • 26
  • 2
  • 3
0

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.

Sandip Nath
  • 622
  • 2
  • 8
  • 18