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

No-nonsense quick start React routing development

Install Enter the following command to install it...

11 Linux KDE applications you didn't know about

KDE Abbreviation for Kool Desktop Environment. A ...

How to install mysql via yum on centos7

1. Check whether MySQL is installed yum list inst...

How to install Nginx in CentOS7 and configure automatic startup

1. Download the installation package from the off...

Some basic instructions of docker

Table of contents Some basic instructions 1. Chec...

Some notes on modifying the innodb_data_file_path parameter of MySQL

Preface innodb_data_file_path is used to specify ...

Use Nginx to build a streaming media server to realize live broadcast function

Written in front In recent years, the live stream...

How to use vue3+TypeScript+vue-router

Table of contents Easy to use Create a project vu...

In-depth understanding of MySQL long transactions

Preface: This article mainly introduces the conte...

React-native sample code to implement the shopping cart sliding deletion effect

Basically all e-commerce projects have the functi...

Tutorial on using hyperlink tags in XHTML

Hyperlink, also called "link". Hyperlin...

Solution to MySql Error 1698 (28000)

1. Problem description: MysqlERROR1698 (28000) so...

Vue large screen display adaptation method

This article example shares the specific code for...