This article describes the installation of Python's virtual environment virtualenv in the ubuntu16.04 environment, and the installation and use in the Windows environment.
Environmental information
Installation
- Download and install python3.6.3
Windows x86-64 web-based installer # 指的是安装的时候需要联网,体积小,下载快,推荐Windows x86-64 executable installer # 指的是使用XXX.exe文件的方式安装,下载体积大Windows x86-64 embeddable zip file # 嵌入式版本
Double click to start the installation, note tick on add Python to path, the other all the way to default;
Test: Enter python at the command line to display the Python interface while the installation is successful;
Attention
- If Python is not recognized, the most likely cause is that the add environment variable is not successful, go to the system environment variable to see it, do not add;
Installing Virtualenv
python3.6.3 version comes with Pip, in order to reduce the installation steps, using PIP installation;
CMD, open the Windows command line;
pip install virtualenvpip install virtualenvwrapper
- After the installation is complete, enter the PIP list to view all the currently installed packages;
Create a virtual environment
- Select a file to hold the virtual environment, such as E:/python3
cd E:python3 # 进入该文件virtualenv envname # 创建一个名字为envname的虚拟环境dir # 查看当前目录可以知道一个envname的文件已经被创建
- Start the virtual environment
# 进入虚拟环境文件cd envname# 进入相关的启动文件夹cd Scriptsactivate # 启动虚拟环境deactivate # 退出虚拟环境
The following are free to install various packages in a virtual environment.
Questions and Details
Every time you need to start a virtual environment, you need to enter the virtual environment of the folder Scripy directory, very inconvenient, you can add scripy path to the system environment variables.
If the system also installs another Python version, such as python2.7.13, and adds its path to the system environment variable, go to the installation file directory, change the Python.exe file to Python2.exe file, and prevent the command from conflict;
If there are multiple versions of Python at the same time, there are multiple versions of PIP, which is required to specify the Python version when using PIP installation.
python -m pip install xxx # python3版本安装包python2 -m pip install xxx # python2版本安装包
- Each time you add a system environment variable, you need to close the current CMD window and restart a window before it takes effect.
VIRTUALENV installation and use of a Python virtual environment under Windows