Ubuntu 18.04-use python3 virtual environment through virtualenv

Software preparation

1. Install pip

Ubuntu 18.04-install pip and change source

2. Install virtualenv

sudo apt-get install python3-virtualenv python-virtualenv
pip3 install virtualenv virtualenvwrapper

Virtual environment usage

1. Create a virtual environment for python3

The same is true for creating virtual links in python2.

# virtualenv -p [指定的python路径] [虚拟环境名] 
virtualenv -p /usr/bin/python3 env-py3

If you encounter an error:
Insert picture description here
Solution: virtualenv error resolution: OSError: Command /home/nano/env-py3/bin/python3-setuptools pkg_resources...

2. Activate and enter the virtual environment

cd env-py3/bin
source activate

Insert picture description here

3. Install python package in virtual environment

Just pip directly, you must not use sudo, otherwise it will be downloaded in the local environment.

pip install xxx

Entering python and python3 in the virtual environment has the same effect.
Insert picture description hereInsert picture description here

4. Exit the virtual environment

deactivate env-py3

5. Delete the virtual environment

Just rm folder directly.

rm env-py3

Reference article:

Guess you like

Origin blog.csdn.net/qq_45779334/article/details/115031529