-
Notifications
You must be signed in to change notification settings - Fork 2
ManagingMultiplePythons
The python language comes with Linux and your particular Linux kernel will depend on a particular version being present. So, you don't want to just replace what it came with.
The proper way to have multiple version that can coexist is to use update-alternatives. Do NOT uninstall the python that came with your operating system - it needs that one to operate.
Here are some instructions to install a newer python
sudo apt update
sudo apt install software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.6
If you intend on compiling against any libraries (/usr/include/python3.6m for example), you need to do:
sudo apt install python3.6-dev
And, we have found problems venv
not working unless you specifically install the one specific to your installation:
sudo apt install python3.6-venv
Assume you have 3 versions of python installed. You need to tell the system which one you want to be running. Run these commands (just once):
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.5 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 2
The last argument is the priority. In this case python3.6 has priority 2, so it has the highest priority. And, you can have as many as you want (not limited to 2).
To select one, you then run:
sudo update-alternatives --config python3
This sets up symbolic links so 'python3' maps to the selected one. By default, it will be on auto mode where it picks the highest priority. But you can switch and then switch back later if you need to.