Detailed tutorial on installing Python 3 virtual environment in Ubuntu 20.04

Detailed tutorial on installing Python 3 virtual environment in Ubuntu 20.04

The following are all performed on my virtual machine

1. Install pip3

sudo apt install python3-pip

2. Install the virtual environment

sudo apt install virtualenv
sudo apt install virtualenvwrapper

3. Modify the configuration file to set environment variables

cd ~
vim .bashrc

Add the following two lines to the end of the .bashrc file

export WORKON_HOME=$HOME/.virtualenvs 
source /usr/share/virtualenvwrapper/virtualenvwrapper.sh

The sentence "usr/share/virtualenvwrapper/virtualenvwrapper.sh" is different from other Ubuntu versions. For example, on Ubuntu 18.04, it is "source /usr/local/bin/virtualenvwrapper.sh". You can find the specific file location yourself and fill it in
Tip: If you cannot find virtualenvwrapper.sh, you can use the following command to find the path where the file is located and replace the found path.

sudo find / -name virtualenvwrapper.sh

4. Enable the configuration file

source .bashrc

At this point, you can create a virtual environment normally.

PS: Let's take a look at Python3 to create a virtual environment

Purpose

Use virtual environments to isolate Python libraries between different projects

Creating a Virtual Environment

Python3 has a built-in venv module. First, create a project directory, enter the directory, and execute

python3 -m venv venv

Activate the virtual environment

Before starting work, activate the corresponding virtual environment:

.venv/bin/activate

On Windows:

venv\Scripts\activate

Once activated, your terminal prompt will display the name of the virtual environment.

Install the corresponding modules, such as:

pip install Flask

Summarize

This is the end of this article about installing Python 3 virtual environment in Ubuntu 20.04. For more information about installing Python 3 virtual environment in Ubuntu 20.04, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • How to upgrade Python on Ubuntu 16 and 18 to the latest Python 3.8
  • How to install, uninstall and delete python-igraph in linux ubuntu
  • Implementation steps for installing Python 3.9 on Ubuntu 16
  • Detailed tutorial on installing python3.7 for ubuntu18
  • Detailed explanation of installing Python 3.7 and pip3 in Ubuntu 16.04 and switching to the default version
  • The process of installing and uninstalling python3.8 in Ubuntu

<<:  How to use not in to optimize MySql

>>:  Vue implements file upload and download

Recommend

Implementing login page based on layui

This article example shares the specific code of ...

About the overlap of margin value and vertical margin in CSS

Margin of parallel boxes (overlap of double margi...

MySQL 8.0.22.0 download, installation and configuration method graphic tutorial

MySQL 8.0.22 download, installation and configura...

Floating menu, can achieve up and down scrolling effect

The code can be further streamlined, but due to t...

Nginx URL rewriting mechanism principle and usage examples

URL rewriting helps determine the preferred domai...

Summary of web designers' experience and skills in learning web design

As the company's influence grows and its prod...

Docker deploys nginx and mounts folders and file operations

During this period of time, I was studying docker...

Let's take a look at some powerful operators in JavaScript

Table of contents Preface 1. Null coalescing oper...

A brief talk about Rx responsive programming

Table of contents 1. Observable 2. Higher-order f...

How to disable foreign key constraint checking in MySQL child tables

Prepare: Define a teacher table and a student tab...