Step 1 – Verifying Python version
Ubuntu should have Python 3.x already installed. However, we will verify this with the command below:
python3 -V
Output:
If you get an error: bash: python3: command not found you can download python using apt
sudo apt update
sudo apt install python3.8
Next, we will install pip. A tool that will install and manage programming packages for python.
sudo apt install -y python3-pip
Now we can install python packages with the command:
pip3 install “package_name”
Replace “package_name” with the package you want to install
Let's install some development tools!
sudo apt install -y build-essential libssl-dev libffi-dev python3-dev
Step 2 – Configuring your Environment
Configuring a virtual environment will keep your python projects isolated from other projects. To do this we will be installing the venv module:
sudo apt install -y python3-venv
Next, let's make a directory for our environment and change to that path.
mkdir Myenvironment
cd Myenvironment
Now we can create our python environment
python3 -m venv my_env
Let's verify that the environment was created with the ls command
ls my_env
Output:In order to use the environment we created, we need to activate it
source my_env/bin/activate
You should now see your environment activated with (my_env) to the left of your terminalStep 3 Create your first program
Use your favorite command line text editor, in my case I'm using nano, and create a file named hello.py
nano hello.py
Add the following line in your text editor
print(“Hello, World!”)
Once saved, you can execute hello.py
python hello.py
Output:You have now installed a python programming environment and created your first program. Have fun!