Because of the numerous versions of Python, there are also Python2 and Python3 debates, so some packages or third-party libraries are prone to version incompatibility issues.
Passvirtualenv
This tool, you can build a series of
虚拟的python环境
, and then install the required packages in each environment (with
pip
Use), this series of environments are isolated from each other. As a standalone environment, version issues are not easily available and are also easy to deploy.
2 installation
Pip Install Virtualenv
3 Basic use of VIRTUALENV 3.1 create a virtual environment
Virtualenv venv
To specify the Python interpreter for the environment:
Virtualenv-p C:\python27\python.exe venv
3.2 Activating a virtual environment
Activate Venv
3.3 Stopping a virtual environment
Deactivate
3.4 Deleting a virtual environment
Delete the directory directly.
Rmvirtualenv venv
4 Virtualenvwrapper
In order to use the virtualenv more convenient, you can rely onvirtualenvwrapper
4.1 Installing Virtualenvwrapper
Pip Install Virtualenvwrapper-win
4.2 Creating a virtual environment
The virtual environment created by default is located in C:\Users\username\envs and can be passed through environment variablesWORKON_HOME
To customize.
By computer--Properties--Advanced system settings--environment variables--NEW "variable name" in System variables: workon_home, Variable value: "Your custom Path".
Execute this command to create a first virtual environment:
Once created, the environment is automatically activated, taking note of changes to the shell prompt:
(venv) c:\>
4.3 List all Virtual environments
Lsvirtualenv
4.4 Activating a virtual environment
Workon venv
4.5 Entering the Virtual environment directory
Cdvirtualenv
4.6 Enter the Site-packages directory of the virtual environment
Cdsitepackages
4.7 Listing all packages for the Site-packages directory
Lssitepackages
4.8 Stopping a virtual environment
Deactivate
4.9 Deleting a virtual environment
Rmvitualenv venv
5 Rebuilding the Python Environment 5.1 freezing the environment
Called冻结(freeze)
Environment is to fix the package of the current environment:
Pip Freeze >packages.txt # Install package list saved to file Packages.txt
5.2 Rebuilding the Environment
重建(rebuild)
The environment is in the deployment, install the corresponding version of the package in the production environment, do not appear version compatibility issues:
Pip Install-r packages.txt
With Pip, you can batch install the corresponding version of the package, quickly rebuild the environment, complete the deployment
Installing the Python virtual environment under Windows Virtualenvwrapper-win