I. Why use a virtual environment
Virtual environment is a private copy of the Python interpreter, in this environment, you can install the package private and will not affect the global system installed Python interpreter.
All installation package in this virtual environment, this is for the environment, will not be used by the outside world.
Each program code to create a virtual environment to ensure that the program can only access the virtual environment package, so as to maintain clean and tidy global interpreter, making it only as a source to create a virtual environment.
Virtual environment is very useful, you can avoid confusion and the package version of the conflict in the Python interpreter system. Important is different virtual environments can build different versions of python, create time to choose? ? ]
II. Create a virtual environment ready
- Python version installed. [I] local version on a python3.7
- Installation virtualenv.
- pip install -i https://pypi.douban.com/simple virtualenv
III. Creating a virtual environment
After the successful installation by the above steps, we can create a virtual environment: virtualenv virtual environment name.
virtualenv [-p python path environment] <Virtual Environment Name (custom)> + // never used path that python
activation:
Exit the virtual environment: deactivate
These are the basic usage, to use the virtual environment, you must first change to the directory activated in order to use the terminal to run the python interpreter that environment. Otherwise use the global interpreter.
IV. High-end configuration of the virtual environment
In fact, we have completed the installation and virtual environments virtualenv used by the above steps, but seriously you need to remember certainly find a top directory for each virtual environment in order to enter the virtual environment and operations,
A lot of trouble, let's simplify our use by another configuration.
1. Installation virtualenvwrapper-win
pip3 install virtualenvwrapper-win -i https://pypi.douban.com/simple
2. Create new ways our virtual environment: mkvirtualenv virtual environment name, but this created a virtual environment in default on the C: \ Users \ username Computer \ Envs directory, bad, configure the look.
3. workon view the configuration of the virtual environment storage space in the virtual path. What configuration directory folder have here.
4. Method
New virtual environment: mkvirtualenv [virtual environment name] -> should be the make convenient shorthand for understanding
Start / switched virtual environment: workon [virtual environment name]
Leave the virtual environment: deactivate
To delete a virtual environment: rmvirtualenv
=================================================================================
virtualenv virtual reality rmvirtualenv (rm delete) mkvirtualenv (mk creation)
activate activation
deactivate disabled