0
TL;DR:
You don’t have to worry about that - which versions of Python are installed for internal system use (in this case Ubuntu) are a problem of it. To work with Python you must learn to manage isolated environments (virtualenv), and install locally the Python version and libraries in the desired version.
Original response
Actually, it is not interesting to leave a single version of Python - you are asking one thing for the wrong problem.
What you need to know is as handle multiple versions of Python on the same machine.
The operating system naturally will install more than one version of Python - even if the main packages of the system are already using Python 3, and the system may have only one Python 3.7, just some software that needs Python 2 as a requirement to be installed (for example, GIMP 2.10)and Python 2.10 will be installed as well.
What you need to learn is to isolate all your Python projects using "virtualenvs" - try to start with this article.
Briefly, a virtualenv, or similar technology, such as "pipenv" or "buildout", allows you to create an isolated environment in a folder, where you will have a pre-selected version of Python, and will install all the modules you need for a given project in that folder. These Python modules are not seen by the operating system, and work independently. Libraries and third-party packages are installed in virtualenv with the command pip
(and never with the system package manager, such as apt
or dnf
/yum
)
It solves a lot, an almost infinite amount of problems. For example, it is common for Python web projects to require dozens of external dependencies - it would be enough if one of those dependencies had a different version of the package than is available as a package from your system, and you wouldn’t be able to develop the system on your computer. (Manually updating a package installed by the system manager is to ensure that you are corrupting your operating system and will need to reformat soon).
So, for example, let’s assume that I’m on an Ubuntu 18.04 and install some application, packaged for Ubuntu, that uses Django as a base. The application uses Django 1.2 - an old version. "apt" will take charge of installing this version of Django in Python system.
Then I decide to start a new system, in Django - I want to use the latest version - the 2.2 - I won’t try to fight and force Django 2.2 into the /usr/lib/python ...folders. just to start, this would destroy the application I installed with APT that uses Django 1.2.
I go in my user folder to create a "virtualenv", with the Python version I want, and install Django and the desired packages there - in general come newer versions than those available from the operating system.
The command sequence is (on Linux):
python3.7 -m venv env
source env/bin/activate
pip install django
In windows:
python3.7 -m venv env
env/Scripts/activate.bat
pip install django
The first line creates the isolated environment, in a folder with the name "env" - this folder contains a Python executable and a lib directory. The second line "activates" virtualenv - in every shell (cmd, in Windows), where you work with the project, have to execute the file commands activate
. This puts the name of virtualenv between relatives at the beginning of the prompt - it will appear something like (env) /home/epx/$
- indicating that virtualenv is active.
And the third line is all that is required to install the latest version of Django, regardless of which Django is available for your system, and independent of other projects on the same computer. And even more: with this it is possible to reproduce the installation of your projects with exactly the same versions of Python packages on any computer - so it is possible to develop your project on Ubuntu 19.04, and put the same to run on a Centos server 2017 - there are a number of things to learn about virtualenv and setup of Python projects, but the basis is this.
It is indicated that you stop installing only with
pip install
and start usingpython3.6 -m pip install
, because this way you have explain the version used. Better than that is if you create the custom of creating virtual environments.– Woss
And do not try to uninstall version 2 of your system, this may break many internal dependencies of the operating system itself
– Woss
There is no way, because there are numerous other software that use Python 2 and Python 3, unfortunately we are all doomed to keep the 2 on the machine for the foreseeable future.
– epx
Only if you use Ubuntu (and similar). The rolling release distributions already come only with Python 3.7
– Woss
... or
pip3 install ...
– JJoao