how to install virtualenv on ubuntu 18.4

tutoriel for install virtualenv on ubuntu 18.4

How to Install Python 3.8 on Ubuntu 18.04?

How to Install Python 3.8 on Ubuntu 18.04?

In this tutorial we'll cover two different ways to install Python 3.8 on Ubuntu 18.04. The first option is to install the deb package from the deadsnakes PPA, and the second one is by building from the source code.

Python is one of the most widely used programming languages in the world. With its simple and easy to learn syntax, Python is a popular choice for beginners and experienced developers. Python is quite a versatile programming language. It can be used to build all kinds of applications, from simple scrips to complex machine learning algorithms.

Python 3.8 is the latest major release of the Python language. It includes many new features such as assignment expressions, positional-only parameters, f-strings support, and more.

Python 3.8 is not available in Ubuntu’s default repositories. In this tutorial, we’ll cover two different ways to install Python 3.8 on Ubuntu 18.04. The first option is to install the deb package from the deadsnakes PPA, and the second one is by building from the source code.

The same steps apply for Ubuntu 16.04 and any Ubuntu-based distribution, including Kubuntu, Linux Mint, and Elementary OS.

Installing Python 3.8 on Ubuntu with Apt

Installing Python 3.8 on Ubuntu with apt is a relatively straightforward process and takes only a few minutes:

  1. Run the following commands as root or user with sudo access to update the packages list and install the prerequisites:

    sudo apt update
    sudo apt install software-properties-common
    
  2. Add the deadsnakes PPA to your system’s sources list:

    sudo add-apt-repository ppa:deadsnakes/ppa
    

    When prompted press Enter to continue:

    Press [ENTER] to continue or Ctrl-c to cancel adding it.
    
  3. Once the repository is enabled, install Python 3.8 with:

    sudo apt install python3.8
    
  4. Verify that the installation was successful by typing:

    python3.8 --version
    
    Python 3.8.0
    

At this point, Python 3.8 is installed on your Ubuntu system, and you can start using it.

Installing Python 3.8 on Ubuntu from Source

In this section, we’ll explain how to compile Python 3.8 from the source.

  1. Update the packages list and install the packages necessary to build Python:

    sudo apt update
    sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget
    
  2. Download the latest release’s source code from the Python download page using wget:

    wget https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tgz
    

At the time of writing this article, the latest release is 3.8.0.

  1. When the download finishes, extract the gzipped archive:

    tar -xf Python-3.8.0.tgz
    
  2. Switch to the Python source directory and execute the configure script which performs a number of checks to make sure all of the dependencies on your system are present:

    cd Python-3.8.0
    ./configure --enable-optimizations
    

The --enable-optimizations option optimizes the Python binary by running multiple tests. This makes the build process slower.

  1. Start the Python 3.8 build process:

    make -j 8
    

For faster build time, modify the -j to correspond to the number of cores in your processor. You can find the number by typing nproc.

  1. When the build process is complete, install the Python binaries by typing:

    sudo make altinstall
    

Do not use the standard make install as it will overwrite the default system python3 binary.

  1. That’s it. Python 3.8 has been installed and ready to be used. Verify it by typing:

    python3.8 --version
    

    The output should show the Python version:

    Python 3.8.0
    
Conclusion

You have installed Python 3.8 on your Ubuntu 18.04 machine, and you can start developing your Python 3 project.

If you have any questions or feedback, feel free to comment below.

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.

Introduction

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:

python


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:

quit()


Then exit the virtual environment:

deactivate


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