I'm starting to study python and I started developing with ubuntu 18.04 and atom editor.
I did not install Python maybe it was included in ubuntu18.04 but I see something very funny.
I'm using the version 2.7 of Python but in the folder I have both libraries of versions 2.7 and 3.0. What should I do if I want to switch and use version 3.0?
Here is the output of the console, someone can give me some information thank you
$ which python
/usr/bin/python
$ python --version
Python 2.7.15rc1
cd /usr/local/lib/ && ls -l
drwxrwsr-x 4 root staff 4096 apr 26 20:23 python2.7
drwxrwsr-x 3 root staff 4096 apr 26 20:18 python3.6 1 2 Answers
python3 is included by default in Ubuntu 18.04 and the command to start the python3 interpreter from the terminal is python3.
To run Python 3.x code in Atom text editor do as follows:
Open the terminal and type:
sudo apt install python-pip python3-pip python-ipykernel python3-ipykernel # python-ipykernel is optional sudo python -m ipykernel install --user sudo python3 -m ipykernel install --userOpen Atom and select the Settings tab -> click the blue Install button located on the left side of the Settings pane. Under the Featured Packages section Hydrogen is the first package in the list because it is the most popular Atom package. Click the blue Install button to install it in Atom. Alternatively you can also search for Hydrogen in the search box in the Install Packages section of the Settings pane. Hydrogen automatically updates the Python kernels for Python 2 and Python 3 each time it is updated.
Restart Atom to enable Hydrogen.
Open a Python 3.x file in Atom by selecting File -> Open File -> browse to a Python file and select it.
Select Packages -> Hydrogen -> Run.
A small popup window will open in Atom asking you to select either Python 2 or Python 3. Select Python 3 by clicking it.
The results of the Python code will be displayed in the same pane in Atom as the Python code.
Installing Python 3 on Ubuntu 18.04.
Start by updating the packages list and installing the prerequisites:
sudo apt update
sudo apt install software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppaWhen prompted press Enter to continue:
Press [ENTER] to continue or Ctrl-c to cancel adding it. Once the repository is enabled, install Python 3 with:
sudo apt install python3At this point, Python 3 is installed on your Ubuntu system and ready to be used. You can verify it by typing:
python3 --versionPython 3.8.2
Swiching From Python 2 To Python 3.
From the comment:
sudo update-alternatives --config pythonWill show you an error:
update-alternatives: error: no alternatives for python3 You need to update your update-alternatives , then you will be able to set your default python version.
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.8 2Then run :
sudo update-alternatives --config pythonSet python3.8 as default.
Or use the following command to set python3.8 as default:
sudo update-alternatives --set python /usr/bin/python3.8