Using Ubuntu 17.04. After update Python 3.5 to 3.6 via terminal according to https://askubuntu.com/a/865569/695385 still showing that version is 3.5.3.
~$ python3 --version Python 3.5.3
How is this installed?
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.Sign up to join this community
After installing Python3.6:
python3 use the new installed Python 3.6 instead of the default 3.5 release, run following 2 commands:
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
Finally, switch between the two Python versions for
python3 via the following command:
sudo update-alternatives --config python3
Then select the
/usr/bin/python3.6 -- automode in choices menu, for me that was
$ python3 -V Python 3.6.9
$ python3 --version Python 3.6.9
How did you upgrade? I suspect you may have a
python3.6 binary somewhere.
Generally speaking, you never want to replace
/usr/bin/python3 with your own fruity versions. Important parts of Ubuntu require their stable Python environments, and largely speaking, that is incompatible with you mucking around.
That all said, having a
/usr/local/bin/python3.6, or whatever in your path) would be fine. If you don't want to type all that in each time, you might want to look at
virtualenv and the various wrapper automation options for it. This has the additional bonus of not threatening your system's
site_packages with your development work.
Use Docker and get the Python image for whatever version you want. It's also easy to update.
FROM python:3.6 RUN apt-get update \ && apt-get install -y --no-install-recommends \ postgresql-client \ && rm -rf /var/lib/apt/lists/* WORKDIR /usr/src/app COPY requirements.txt ./ RUN pip install -r requirements.txt COPY . . EXPOSE 8000
This answer is not specific to
python3.6 but can be used in general.
Assuming the latest version of python to be
# Update apt repo sudo apt update # Install new python3.10 sudo apt install python3.10 python3.10-dev -y # Unlink the python3 command sudo unlink /usr/bin/python3 # Link to python3.10 binary sudo ln -s /usr/bin/python3.10 /usr/bin/python3 # Checking python3 version $ python3 --version Python 3.10.0+
You might face some issue like this with your
apt commands after installing the newer python version
ImportError: No module named apt_pkg
For this you can try below commands to update the socket file link
# Reinstall python3-apt to create python3.10 apt socket file sudo apt-get install python3-apt --reinstall # Link the apt_pkg.so file to python3.10 socket file cd /usr/lib/python3/dist-packages sudo ln -s apt_pkg.cpython-310-x86_64-linux-gnu.so apt_pkg.so
Other option is using PPA:
sudo add-apt-repository ppa:jonathonf/python-3.7 sudo apt-get update sudo apt-get install python3.7
And add Python 3.7 to update-alternatives with priority 1.
Visit https://www.python.org/downloads/source/ to find the latest version. Check the current stable version before pulling for install.