How to install Python3 in Ubuntu20.04 in Virtual Environment
This article mainly shows you how to install Python3 in Ubuntu20.04 in a virtual environment, the content is simple and easy to understand, I hope you can learn, after learning, there will be a harvest, the following let the editor take a look at it.
The following is done on my virtual machine.
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
The above is about how to install Python3 in Ubuntu20.04 in a virtual environment. If you have learned knowledge or skills, you can share it for more people to see.