How to create a virtual Python environment on Ubuntu 20.04 and 18.04

before the start

This tutorial has been tested on Ubuntu 18.04.4 Linux. In addition, I already have Python 3.8 installed on the system.

Step 1: Install Virtualenv module

First, you need to install Virtualenv Python modules on the system. Use pip3 virtualenv Python installation module. This will also other required modules installed on your system.

How to create a virtual Python environment on Ubuntu 20.04 and 18.04

Step 2: Create a virtual environment

After the installation is complete. Let's create an isolated Python environment for your application.

Find your application needed to run Python binary position. In this tutorial, we use the most recent Python 3.8 installed. Which command to use to check the position of Python 3 binaries.

How to create a virtual Python environment on Ubuntu 20.04 and 18.04

You can choose any other Python versions according to application requirements.

Then create isolated Python environment using the following command:

Output:

How to create a virtual Python environment on Ubuntu 20.04 and 18.04

This command creates a local copy of your environment specific to this site. When working on the website, you should activate the local environment, to ensure that the correct version of the tools and software packages.

The third step: work in a virtual environment

After you create a virtual Python environment on Ubuntu systems. You need to activate it by running the following command.

Now, you will see the Python prompt isolation environment. Check the python binary position, use the following command:

How to create a virtual Python environment on Ubuntu 20.04 and 18.04

Now, you use pip to install all the packages will be placed in a virtual environment project folder, install Python and global isolation.

How to create a virtual Python environment on Ubuntu 20.04 and 18.04

Use pip3 mounting module. If you are using openstack, you can use the "nose". E.g:

How to create a virtual Python environment on Ubuntu 20.04 and 18.04

Step four: Disable virtual environment

After completing the work in a virtual environment, simply run the "deactivate" command to exit the isolated environment. Then, you will allow users to use the default shell.

How to create a virtual Python environment on Ubuntu 20.04 and 18.04

Step Five: Remove the virtual environment

How to create a virtual Python environment on Ubuntu 20.04 and 18.04

Guess you like

Origin www.linuxidc.com/Linux/2020-03/162745.htm