Virtualenv is a module used to create a standalone Python environment, and multiple python are independent from each other and can:
1. Install the new kit without permission
2. Different applications can use different versions of the kit
3. Package upgrade does not affect other applications
Virtualenv installation under Ubuntu:
sudo apt-get install python-virtualenv or
sudo pip install virtualenv
How to use:
1. Create a virtual environment named MySite:
Virtualenv MySite
This creates a general default Python2 environment (if direct PIP is installed) because Virtualenv chooses his hosting environment by default
If you want to create a virtual environment that specifies a Python version and does not contain any packages (installed on your own)
virtualenv–p/usr/bin/python3.5--no-site-packages MySite
Use –p to point to the Python environment by--no-site-packages to specify packages that are not dependent on the external Python environment
This makes it easy to create a virtual environment of your own.
2. Enter the virtual environment:
source./mysite/bin/activate
!! Source is a command to enter the virtual environment, and the following path points to the bin/activate in the created virtual environment
Writes based on the current path.
When you enter a virtual environment, the command line changes, with the name of the virtual environment in front of it
After entering the virtual environment, first identify the packages that are in the environment and install the required packages
PIP List # View packages and modules in the current environment
Pip Install "name" #安装所需要的模块
3. Exit the Virtual environment:
Deactivate
4. Delete the virtual environment:
RM–RF MySite #就是一个彻底删除文件夹操作, carefully confirm
Python Virtual Environment: virtualenv