How To Install Python 3 and Set Up a Programming Environment on Ubuntu 18.04

How To Install Python 3 and Set Up a Programming Environment on Ubuntu 18.04

This tutorial will walk you through installing Python and setting up a programming environment on an Ubuntu 18.04 server.

This tutorial will walk you through installing Python and setting up a programming environment on an Ubuntu 18.04 server.


Python is a flexible and versatile programming language, with strengths in scripting, automation, data analysis, machine learning, and back-end development.

This tutorial will walk you through installing Python and setting up a programming environment on an Ubuntu 18.04 server.

Step 1 — Update and Upgrade

Logged into your Ubuntu 18.04 server as a sudo non-root user, first update and upgrade your system to ensure that your shipped version of Python 3 is up-to-date.

sudo apt update
sudo apt -y upgrade

Confirm installation if prompted to do so.

Step 2 — Check Version of Python

Check which version of Python 3 is installed by typing:

python3 -V

You’ll receive output similar to the following, depending on when you have updated your system.

OutputPython 3.6.5

Step 3 — Install pip

To manage software packages for Python, install pip, a tool that will install and manage libraries or modules to use in your projects.

sudo apt install -y python3-pip

Python packages can be installed by typing:

pip3 install package_name

Here, package_name can refer to any Python package or library, such as Django for web development or NumPy for scientific computing. So if you would like to install NumPy, you can do so with the command pip3 install numpy.

Step 4 — Install Additional Tools

There are a few more packages and development tools to install to ensure that we have a robust set-up for our programming environment:

sudo apt install build-essential libssl-dev libffi-dev python3-dev

Step 5 — Install venv

Virtual environments enable you to have an isolated space on your server for Python projects. We’ll use venv, part of the standard Python 3 library, which we can install by typing:

sudo apt install -y python3-venv

Step 6 — Create a Virtual Environment

You can create a new environment with the pyvenv command. Here, we’ll call our new environment my_env, but you can call yours whatever you want.

python3.6 -m venv my_env

Step 7 — Activate Virtual Environment

Activate the environment using the command below, where my_env is the name of your programming environment.

source my_env/bin/activate

Your command prompt will now be prefixed with the name of your environment:

Step 8 — Test Virtual Environment

Open the Python interpreter:


Note that within the Python 3 virtual environment, you can use the command python instead of python3, and pip instead of pip3.

You’ll know you’re in the interpreter when you receive the following output:

Python 3.6.5 (default, Apr  1 2018, 05:46:30) 
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.

Now, use the print() function to create the traditional Hello, World program:

print("Hello, World!")

OutputHello, World!

Step 9 — Deactivate Virtual Environment

Quit the Python interpreter:


Then exit the virtual environment:


Further Reading

An A-Z of useful Python tricks

A Complete Machine Learning Project Walk-Through in Python

Machine Learning: how to go from Zero to Hero

Learning Python: From Zero to Hero

Automated Machine Learning on the Cloud in Python

Introduction to PyTorch and Machine Learning

Python Tutorial for Beginners (2019) - Learn Python for Machine Learning and Web Development

How to get started with Python for Deep Learning and Data Science

How To Use Vuls as a Vulnerability Scanner on Ubuntu 18.04

Complete Python Bootcamp: Go from zero to hero in Python 3

Machine Learning A-Z™: Hands-On Python & R In Data Science

Complete Python Masterclass

Python and Django Full Stack Web Developer Bootcamp

python ubuntu

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Basic Data Types in Python | Python Web Development For Beginners

In the programming world, Data types play an important role. Each Variable is stored in different data types and responsible for various functions. Python had two different objects, and They are mutable and immutable objects.

How To Compare Tesla and Ford Company By Using Magic Methods in Python

Magic Methods are the special methods which gives us the ability to access built in syntactical features such as ‘<’, ‘>’, ‘==’, ‘+’ etc.. You must have worked with such methods without knowing them to be as magic methods. Magic methods can be identified with their names which start with __ and ends with __ like __init__, __call__, __str__ etc. These methods are also called Dunder Methods, because of their name starting and ending with Double Underscore (Dunder).

How to Install Pyenv on Ubuntu 18.04

How to Install Pyenv on Ubuntu 18.04 - What is Pyenv? Pyenv is a fantastic tool for installing and managing multiple Python versions. It enables a developer to quickly gain access to newer

How to Install Microsoft Teams on Ubuntu 20.04

In this tutorial, we will show you how to install Microsoft Teams on Ubuntu 20.04 machine. we can install teams using Debian installer file or by adding microsoft repository.

Python Programming: A Beginner’s Guide

Python is an interpreted, high-level, powerful general-purpose programming language. You may ask, Python’s a snake right? and Why is this programming language named after it?