Windows + Python + virtualenv environment Configuration
Virtualenv is a common virtual environment in Python. It can be understood to belongPython Virtual Machine.
On Linux and Mac systems, the virtualenv environment is easy to configure, but it is troublesome on the windows platform and can be recorded and shared with you.
Install Python
Note: The Python version configured this time is2.7.XIn the old version, some libraries in the new version of Python 3.X are not supported, so it is not used.
The configuration of Python 2.7.x in window is not much to mention. There are a lot of online materials. For more information, see here. Only when downloadingDownload 2.7.X. At the same time, rememberAdd the Python directory to the system directory Path.
Install pip
What is pip? The answer on the official website is:A tool for installing and managing Python packages.
Intuitively, after installing pip and adding it to the Path system directory, the command line (CMD) has an additional command named pip. You can use this command to automatically download and install Python's various third-party libraries.
For the pip installation process, see here.
To put it bluntly, it is to execute two. py files in Python under the command line: ez_setup.py and get-pip.py. At the same time, rememberAdd the Scripts folder to the system directory Path.
Install virtualenv
After pip is installed, it is easy to install virtualenv. Enter the following command in the cmd command line:
>pip install virtualenv
Wait until automatic download and installation are completed. Go to a folder where you want to create a virtual Python environment and enter the following command:
>virtualenv venv
Let's see if there is another venv folder under the current directory of cmd? This folder is used to save the Python virtual environment.
Enable or disable virtualenv
In windows, enter the venv (Virtual Environment folder you created) folder and enter the following command:
>Scripts\activate
Always cd find the inside of the Scripts file, and directly execute the file activate under the command line (just like the. exe file, just enter the name in the command line)
At this time, you will find that the command line becomes like this:
The previous one (venv) represents entering the virtual environment. Here, you can use python, pip, and other commands, all of which are configured by virtualenv. You can download other libraries by yourself.
To disable the virtual environment, enter deactivate and press Enter.
Note:
The virtual environment created by virtualenv and the Python environment of the hostCompletely unrelatedThe database configured on your host cannot be used directly in virtualenv. You must use pip install to install the configuration again in the virtual environment.