Excerpt from: Https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/ 001432712108300322c61f256c74803b43bfd65c6f8d0d0000
When developing a Python application, the system installs only one version of the Python3:3.4. All third-party packages will be pip
installed in the Python3 site-packages
directory. (Linux)
If we were to develop multiple applications at the same time, those applications would share a python, which is the Python 3 installed in the system. What if application a requires Jinja 2.7 and application B needs Jinja 2.6?
In this case, each app may need to have a "standalone" Python runtime environment. Virtualenv is a python run environment that is used to create a "quarantine" for an application.
First, we use the pip
installation virtualenv:
$ PIP3 Install virtualenv
Then, assuming that we are going to develop a new project, we need a separate Python runtime environment to do this:
The first step is to create the directory:
mkdir MyProject
CD MyProject
virtualenv --no-site-packages venv
' /usr/local/.../python.framework/versions/3.4 ' in venv/bin/python3.4 in venv/bin/pythoninstalling setuptools, pip, Wheel ... Done.
Command virtualenv
to create a standalone Python runtime environment, we have added parameters --no-site-packages
so that all third-party packages that have been installed into the system Python environment will not replicate, so that we get a "clean" without any third-party packages Python runtime environment.
The new Python environment is placed in the directory under the current directory venv
. With venv
This Python environment, you can source
enter the environment:
Venv>scripts\activate
(venv) F:\apython_democode\cn\douzi\lesson99_virtualenv\myproject\venv>
Notice there's a venv.
Python Learning Notes (43) virtualenv (Create a set of "isolated" python runtime environments)