Step 1 – Verifying Python version
Ubuntu should have Python 3.x already installed. However, we will verify this with the command below:
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
Lets 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, lets make a directory for our environment and change to that path.
Now we can create our python environment
python3 -m venv my_env
Lets verify that the environment was created with the ls command
In order to use the environment we created we need to activate it
You should now see your environment activated with (my_env) to the left of your terminal
Step 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
Add the following line in your text editor
Once saved, you can execute hello.py
You have now installed a python programming environment and created your first program. Have fun!