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?
Best Answer
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.
(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 computerYou may then run
update-alternatives
with the--config
option so that you may select which version you want to choose to be the defaultUse 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