Python Learning Notes (43) virtualenv (Create a set of "isolated" python runtime environments)

Source: Internet
Author: User
Tags virtualenv

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.