How to Install Python 3.6.5 on My Ubuntu 19.10 That Already Contains Python 3.7.5

I don't have python but I have python3

Recent Ubuntu versions do not install python 2 by default, as python 2 is now "dead". However, the command python is not (yet) linked to python 3, to avoid some confusion; traditionally, python was for python 2 while python3 was for python 3.

In case you want to change this behavior and use python to run python 3, try installing a package named 'python-is-python3'. Then you can run python --version and see that it points to python 3.

In theory it might cause confusion for some legacy programs, but I haven't seen any issue so far for about a year.

In 20.04 LTS, the python included in the base system is Python 3.8. Python 2.7 has been moved to universe and is not included by default in any new installs.

Remaining packages in Ubuntu which require Python 2.7 have been updated to use /usr/bin/python2 as their interpreter, and /usr/bin/python is not present by default on any new installs. On systems upgraded from previous releases, /usr/bin/python will continue to point to python2 for compatibility. Users who require /usr/bin/python for compatibility on newly-installed systems are encouraged to install the python-is-python3 package, for a /usr/bin/python pointing to python3 instead.

— https://wiki.ubuntu.com/FocalFossa/ReleaseNotes

Ubuntu: Python command not found but apt says it's already installed

It was saved as python3 instead of python

ubuntu broken python installation by mistake

After some more research, I've founded a post related to Debian. Handling some modifications for Ubuntu 16.04, tried this guide and works everything now:

Step 1.

cd /tmp
apt-get download libpython3.5-minimal
apt-get download python3.5-minimal
apt-get download python3-minimal
apt-get download libpython3.5-stdlib
apt-get download python3.5

Step 2.

rm -rf /usr/local/lib/python3.5*
rm -rf /usr/local/bin/python3.5*
update-alternatives --remove python3 /usr/local/bin/python3.5
hash -r # removes cached python3 binary path

Step 3.

cd /tmp
dpkg-deb -x libpython3.5-minimal_3.5.2-2ubuntu0~16.04.13_amd64.deb missing
dpkg-deb -x libpython3.5-stdlib_3.5.2-2ubuntu0~16.04.13_amd64.deb missing
dpkg-deb -x python3.5-minimal_3.5.2-2ubuntu0~16.04.13_amd64.deb missing
dpkg-deb -x python3.5_3.5.2-2ubuntu0~16.04.13_amd64.deb missing
dpkg-deb -x python3-minimal_3.5.1-3_amd64.deb missing

Step 4.

cd /tmp/missing
ls -lR /tmp/missing # if you are curious about overwriting your HD
sudo cp -rpfv /tmp/missing/* /

Step 5.

python3
Python 3.7.3 (default, Apr 3 2019, 05:39:12)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

Import and test new version:

>>> import sys
>>> print(sys.version_info)
sys.version_info(major=3, minor=7, micro=3, releaselevel='final', serial=0)
>>>
>>> quit()

Step 6.

rm -rf /tmp/missing

Step 7.

dpkg -s -a python3.5 | grep  reinstreq
# Any listing also needs to be reinstalled along with python3
apt-get install --reinstall python3

Step 8.

apt-get autoclean
apt-get autoremove
# (see the packages that will autoremove, you need to reinstall it again after: apt-get install --fix-broken --reinstall <<packages>>)

Step 9.

Try to install common prop.

sudo apt install software-properties-common

If it works, now the installation is done.


I've tried this for Ubuntu 16.04, with working Python2.7 installation but not with Python3, or Python3.5. The original installation I've was for Python3.5, that's why tried to install that version instead newest.

How to Install pip for python 3.7 on Ubuntu 18?

In general, don't do this:

pip install package

because, as you have correctly noticed, it's not clear what Python version you're installing package for.

Instead, if you want to install package for Python 3.7, do this:

python3.7 -m pip install package

Replace package with the name of whatever you're trying to install.

Took me a surprisingly long time to figure it out, too. The docs about it are here.

Your other option is to set up a virtual environment. Once your virtual environment is active, executable names like python and pip will point to the correct ones.



Related Topics



Leave a reply



Submit