10

I have Python2.7 and many libraries that I use to run most of my code. However, I'd like to install python3 alongside it so that I can occasionally use it to test out some new code that I have recently obtained.

How can I install this to avoid causing any issues for the Python2.7 and the installed libraries?

1
  • 5
    Python3 is typically installed by default, execute it in a terminal by running python3 instead of python
    – Baa
    May 13, 2019 at 21:01

1 Answer 1

17

As Hugo stated in the comment above, python3 should already be installed and you can run it by using python3 in the terminal as he mentioned.

Setting up virtual Environments:
You can also setup virtual python environments using pip. Install pip with the following command.

sudo apt install python-pip

(to install pip3 for python3, use this command sudo apt install python3-pip)
Now that you have pip installed you can refer to the instructions at this link to learn how to setup these virtual environments for testing various python versions and packages

Switching between python versions using update-alternatives:
If setting up virtual environments is not what you want to do, then you can also use update-alternatives to switch between python version. Run these two commands first, but make sure the python versions match what you have on your computer

sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.5 2

You may then run update-alternatives with the --config option so that you may select which version you want to choose to be the default

$ sudo update-alternatives --config python

Use the interactive menu to select which version you would like to use as the default. In order to check if your changes have worked you can use python --version

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .