Introduction and use of Python's virtualenv tools __python

Source: Internet
Author: User
Tags virtual environment virtualenv

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

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.