Python version in Ubuntu 18.04
Solution 1
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 --user
Open 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.
Solution 2
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/ppa
When 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 python3
At this point, Python 3 is installed on your Ubuntu system and ready to be used. You can verify it by typing:
python3 --version
Python 3.8.2
Swiching From Python 2 To Python 3.
From the comment:
sudo update-alternatives --config python
Will 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 2
Then run :
sudo update-alternatives --config python
Set python3.8 as default.
Or use the following command to set python3.8 as default:
sudo update-alternatives --set python /usr/bin/python3.8
Related videos on Youtube
Piero
Updated on September 18, 2022Comments
-
Piero over 1 year
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
-
Daniele Santi over 5 yearsHello and welcome to AskUbuntu! On my system I have both
/usr/bin/python
and/usr/bin/python3
. Have you triedpython3 --version
?
-
-
Piero over 5 yearsI tried to run .py file from hydrogen and a popup with the following error message is shown Also, it seems that it has not even installed the tool pip No Kernels Installed No kernels are installed on your system so you will not be able to execute code in any language. No kernel for grammar Python found Check that the language for this file is set in Atom and that you have a Jupyter kernel installed for it. To detect your current Python install you will need to run:
-
karel over 5 years@Piero edited my answer in reply to your comment. The edit in step 1. will force Hydrogen to update the locations of the installed Python kernels in Atom's settings.