1.virtualenv Tools Introduction
In our daily Python project development, for example, in addition to flask based projects, there will be other projects to use Python. As the project grows, it faces problems using different versions of Python, or at least a different version of the Python library. In front of you is: the library is often not backward compatible, unfortunately, any mature application is not 0 dependent. If two projects are dependent on conflicts, it can be cumbersome.
And virtualenv can be used to solve the problem of Python's multiple version environment. Its rationale is to install a set of Python for each project, and multiple sets of python coexist. But instead of actually installing multiple standalone Python copies, it uses a clever way to keep different projects in their separate environments.
Use of 2.virtualenv
(1) Installation of virtualenv
Pip install virtualenv or
easy_install virtualenv or
apt-get install (Ubuntu system)
(2) The use of virtualenv
Execute virtualenv my-env to create a Python virtual environment called my-env;
Execute the source my-env/bin/activate command to activate the My-env Python virtual environment and go into the python virtual environment, and then do all sorts of things. Note that there is a change in the terminal prompt, but you can switch to any directory execution, not limited to the MY-ENV directory;
Execute Deactivate command, you can exit My-env python virtual environment, it should be noted that VIRTUALENV virtual environment after the exit, the virtual environment started in the service process, and will not quit OH.
Note:
When we create a Python virtual environment, we can specify the Python version to use for the virtual environment, as follows (it would be nice to use the-p parameter to indicate the path of the Python interpreter):
Virtualenv-p/usr/bin/python2.7 ENV2.7 #创建python2.7 Virtual Environment
virtualenv-p/usr/bin/python3.4 ENV3.4 # Creating a python3.4 Virtual environment