This guide will walk you through installing Python and configuring a programming environment on an Ubuntu 18.04 server. The tutorial Installation of Python 3 and Setting up a Programming Environment on an Ubuntu 18.04 Server has a more extensive version of this article with more detailed explanations of each step.
Step 1: Update and upgrade if needed
Log in as a sudo user without a root access to the Ubuntu 18.04 server, then execute a system upgrade and ensure that the Python 3 version supplied is up to current.
sudo apt update sudo apt -y upgrade
If prompts then confirm the installation.
Step 2: Verify the Python version.
Use the following command to determine the version of Python 3 that is installed:
Depending on when your system was updated, you should get something like this.
Outpu Python 3.6.7
Step 3: Install pip
To manage Python software packages, you must install the pip tool, which installs and manages libraries and modules for your projects.
sudo apt install -y python3-pip
The following command can be used to install Python packages:
pip3 install package_name
Package name can refer to any Python package or library, such as Django for web development or NumPy for scientific computing. NumPy can be installed with the pip3 install numpy command.
Step 4. Installing the extra tools
To provide a solid basis for our programming environment, you can install the following extra packages and development tools:
sudo apt install build-essential-libssl-dev libffi-dev python3-dev
Step 5: Set up venv
Virtual environments provide separate area on the server for Python projects. We’ll be using venv, which is part of the standard Python 3 package. You must type: to install it.
sudo apt install -y python3-venv
Step 6: Construct a virtual environment
The pyvenv command can be used to build a new environment. We’ll call our new environment my env, but you can call it whatever you like.
python3.6 -m venv mu_env
Step 7: Start the virtual environment.
Use the following command to activate the environment. where my env is the name of your development environment
The command line will now be prefixed with the name of your environment:
Step 8: Inspect the virtual environment
Start the Python interpreter by typing:
You can use python instead of python3 and pip instead of pip3 in the Python 3 virtual environment.
When you see the following, you know the interpreter is active:
Python 3.6.5 Python 3.6.5 (default, Aug 28 2022, 10:05:12) [GCC 7.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> Now use print() to create a traditional Hello, World: print("Hello, World!")
Output Hello there, World!
Step 9 – Exit the virtual environment
Terminate the Python interpreter:
Shuts down the virtual environment: