Install Python on Ubuntu and set up a Programming Environment
Step 1 – Verifying Python version
Ubuntu should have Python 3.x already installed. However, we will verify this with the command below:
python3 -VOutput:
If you get an error: bash: python3: command not found you can download python using apt
sudo apt updatesudo apt install python3.8Next, we will install pip. A tool that will install and manage programming packages for python.
sudo apt install -y python3-pipNow 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-devStep 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-venvNext, let's make a directory for our environment and change to that path.
mkdir Myenvironmentcd MyenvironmentNow we can create our python environment
python3 -m venv my_envLet's verify that the environment was created with the ls command
ls my_envOutput:In order to use the environment we created, we need to activate it
source my_env/bin/activateYou 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.pyAdd the following line in your text editor
print(“Hello, World!”)Once saved, you can execute hello.py
python hello.pyOutput:You have now installed a python programming environment and created your first program. Have fun!