Default python3
on Ubuntu 14.04 is of 3.4.3
but I want to use 3.6.3
instead.
I followed commands below to install 3.6.3<
Hi the real problem is described here: https://stackoverflow.com/a/41722610/7933710 TLDR: Using a ppa on older Ubuntu systems is not consistent.
To repair your system you'll have to remove python3.6:
apt-get remove --purge python3.6
add-apt-repository -r ppa:jonathonf/python-3.6
Then download the source and build from source and prepare the system for building:
wget https://www.python.org/ftp/python/3.6.7/Python-3.6.7.tgz
Now prep the system for building:
apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev
All these steps are from the guide here https://realpython.com/installing-python/#compiling-python-from-source
Now configure, make, make altinstall (important)
tar xvf Python-3.6.7.tgz
cd Python-3.6.7/
./configure --enable-optimizations --with-ensurepip=install
make -j 8
make altinstall
The
-j 8
means run on 8 cores. Of course if you have less then use the appropriate number. It will not cause a crash in any case.
Now verify the install by runnning
python3.6 -V
which python3.6
Copy the path of python3.6
, it should be either /usr/bin/python3.6
or /usr/local/bin/python3.6
You can now use the update-alternatives
to manage all python versions on your machine
ls /usr/bin/python* # e.g. /usr/bin/python2.7 /usr/bin/python3.4 /usr/bin/python3.6
update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
update-alternatives --install /usr/bin/python python /usr/bin/python3.4 1
update-alternatives --install /usr/bin/python python /usr/local/bin/python3.6 2
The number 2
signifies the priority for running python on your machine. In this case 2 > 1, so you'll prefer python3.6. If you want to change to version 3.4 you can just run update-alternatives --config python
which is an interactive configurator.
Now you can use python -m pip -V
to verify pip is working correctly. You can also use pip3.6 to install packages.