Unable to upgrade from Python2 to Python3 (Ubuntu 19.04)

109 views Asked by At

I had python2 installed in my ubuntu (19.04) and I wanted to get it upgraded to 3.7. I installed the 3.7 but still the version showed as 2.7. but I could run python3 and go to the console and python3.7 executable was available in /usr/bin. Did try all the tricks available in internet without any luck. then I decided to delete python2.7 executable from the /usr/bin and now I cannot even run pip as it tries to find the deleted 2.7 I guess. Getting the following message.

bash: /usr/bin/pip: /usr/bin/python: bad interpreter: No such file or directory

I don't know why it's still trying to find 2.7 like ex girl friend when 3.7 is installed and available in the machine.

2

There are 2 answers

0
Qasim On

Did you set up a path for python 3.7 in your .bashrc file? If not, try that and that should help.

Usually a path is something like:


$ export PATH=$HOME/Nek5000/bin:$PATH

1
Tanmay Pandey On

First, run an update to make sure that there aren’t newer versions of the required packages.

sudo apt update --fix-missing

Next, you can try forcing Apt to look for and correct any missing dependencies or broken packages. This will actually install any missing packages and repair existing installs.

sudo apt install -f

(Source)

Also, always remember - never install directly in global environment. You should always create a local environment first(i recommend venv) as there are very high chances you can break something globally. You can create a local environment by -

python3 -m venv tutorial-env

where tutorial-env is the name of your environment. To activate this environment, you should run

source tutorial-tutorial-env/bin/activate