Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How Ubuntu20.04 installs Python3's virtual environment

Shulou Source: shulou.com Published: 2022-05-31 11:20:44 10月17日 Update

This article mainly introduces the relevant knowledge of "how Ubuntu20.04 installs the virtual environment of Python3". The editor shows you the operation process through the actual case. The method of operation is simple, fast and practical. I hope that this article "how to install the virtual environment of Python3 in Ubuntu20.04" can help you solve the problem.

1. Install pip3

Sudo apt install python3-pip

two。 Install a virtual environment

Sudo apt install virtualenvsudo apt install virtualenvwrapper

3. Modify the configuration file to set environment variables

Cd ~

Vim .bashrc

Add the following two lines after the .bashrc file

Export workon_home=$home/.virtualenvs source / usr/share/virtualenvwrapper/virtualenvwrapper.sh

Among them, the sentence "usr/share/virtualenvwrapper/virtualenvwrapper.sh" is different from other ubuntu versions. Other bosses are "source / usr/local/bin/virtualenvwrapper.sh" on ubuntu18.04, and the specific file location can be found and filled in.

Tip: if you can't find virtualenvwrapper.sh, you can use the following command to find the path where the file is located and change the path you found.

Sudo find /-name virtualenvwrapper.sh

4. Enable profile

Source .bashrc

At this point, the virtual environment can be created normally.

Ps: let's take a look at python3 to create a virtual environment

Purpose

Virtual environments are used to isolate python libraries between different projects

Create a virtual environment

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

Python3-m venv venv

Activate the virtual environment

Before you start working, activate the appropriate virtual environment:

. Venv/bin/activate

Under windows:

Venv\ scripts\ activate

When activated, your terminal prompt displays the name of the virtual environment.

Install the appropriate modules, such as:

Pip install flask

This is the end of the introduction to "how Ubuntu20.04 installs the virtual environment of Python3". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Tags: Environment file different activation knowledge module directory industry path project configuration utility inter location content variable can make name command utility Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Apple OPPO Reno Xiaomi Docker