I have a problem.

I don't know how, but I have 2 versions of python installed.

  1. Python 2.7
  2. Python 3.7

Now all my packages are installed in python 2.7 (The version I am using), but I want to upgrade EVERYTHING to python 3.7. What is the best way and can someone tell me what to do step by step?

  • 2
    If you are using Ubuntu, THE BEST way is not to do it. Otherwise you'll break your system – Pilot6 Aug 17 '19 at 12:33
  • So you are saying that I should stay in version 2.7? I mean, there must be a way to upgrade it somehow? – A. Vreeswijk Aug 17 '19 at 12:34
  • You have both versions installed. – Pilot6 Aug 17 '19 at 12:35
  • Yeah, but how can I transfer all my packages installed with pip to my newer version? – A. Vreeswijk Aug 17 '19 at 12:36
  • 2
    Some of the core programs are written for Python 2.7, other are written for different versions... so I wouldn't touch them. – pa4080 Aug 17 '19 at 12:37

In Ubuntu 18.04 and newer, Python3 is installed by default, Python2 is not.
The command python refers ONLY to Python2. Use the command python3 for Py3. Avoid mixing them up.

When using pip, it's the same: pip uses Python 2, pip3 uses Python 3.

Make sure you have both versions of Pip installed.

    sudo apt install python-pip      // Python 2 example
    sudo apt install python3-pip     // See the difference?
  1. List the Python 2 (pip) packages that you have installed

    pip freeze
  2. Install the Python 3 versions

    pip3 install package another_package yet_another_package
  3. Uninstall the Python 2 versions

    pip uninstall package another_package yet_another_package

Using Pip won't affect debs or other kinds of packages. If you had Python 2 deb packages installed, then you still have them installed.


If you are talking about packages installed with pip, you cannot upgrade them, but you have to install them again with a pip version which corresponds with a Python 3 version.

Generally, you should not install packages into the global Python installation, as dependency conflicts could arise.

You could either manually create a virtual environment and install the packages in there, or you could use a tool like pipx which automatically creates a virtual environment for every installed package.


Not really a solution but, you could use both.

running in terminal python3 instead of python you can run python 3 in the latest version you have downloaded. It goes the same for the packages. Installing packages by running pip3 instead of pip you are installing packages suitable for python 3. Of course its also the same for idle and when you are running python scripts


Ubuntu 18.04 and later

  1. Upgrade all of the currently installed python 2.7 packages to Python 3.7.

    1a. Install Synaptic package manager.

    sudo apt install synaptic

    1b. Open Synaptic, select Installed from the left pane and type python in the search box.

    enter image description here

    1c. Upgrade installed Python 2 packages that were installed by apt to Python 3. You can do this in the Synaptic interface.

    1d. Uninstall all Python packages that were installed by pip.

    pip freeze | xargs pip uninstall -y

    If you don't run this command with sudo or as root it won't uninstall any packages that were globally installed by pip which you may need, but it may leave behind a few Python 2 packages that were globally installed by sudo pip or pip run as root. I recommend that you leave these globally installed by sudo pip or pip run as root packages installed for now at least until you learn how wild the pip freeze command is.

  2. Uninstall Python 2.7.

    sudo apt remove python2.7-minimal python2.7
  3. Install deborphan

    sudo apt install deborphan  
  4. Run deborphan

  5. Uninstall all orphaned Python 2 packages. Maybe there won't be any orphaned Python 2 packages to uninstall if Synaptic caught them all.

Please note that I'm using apt as a replacement for pip whenever possible because I think that pip is a lame excuse to install a lot of second rate Python packages compared to the same first rate Python packages that could be installed from the default Ubuntu repositories. Don't take the bait of using pip to upgrade every installed Python package to the latest version for Python 3.7. If you get into the habit of installing Python packages from the default Ubuntu repositories instead of with pip, you will avoid getting mired in hopeless complexities. Using pip with sudo is a trap, and you can install whatever Python packages you want without sudo in a Python virtual environment instead.

  • 1
    Won't that uninstall lots of useful things? – Pilot6 Aug 17 '19 at 12:37
  • With "Upgrade all of the currently installed python 2.7 packages to Python 3.7.", how can I do that? – A. Vreeswijk Aug 17 '19 at 12:38
  • It seems that the OP wants to replace all packages installed with pip with their respective versions with pip3. – Archisman Panigrahi Aug 17 '19 at 12:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.