Python Environmental Management--virtualenvwrapper

Source: Internet
Author: User

Problems encountered:

During the recent development and deployment process, when multiple servers were deployed, it was found that the management of libraries and packages was confusing, with two major versioning issues:

    1. Because of the business needs, the code is deployed separately on different servers, and each time a deployment is repeated the installation package is not determined to be the same as the package version in the development environment
    2. In the local environment, different programs have to use different versions of libraries and packages, in order to prevent confusion between different programs

Therefore, it is necessary to manage the environment so as not to confuse the development environment and the running environment.

Solve the problem:

At first I tried to use the virtualenv, then found the virtualenv extension tool-----virtualenvwrapper, and found that this makes the environment management become more easy.

Function:

    • Integrate all of your virtual environments into one directory.
    • Manage (new, remove, copy) all virtual environments.
    • You can use a single command to switch between virtual environments.
    • The name of the Tab-complete virtual environment.

Installation:

Pip Install Virtualenvwrapper

Use:

    • List Virtual environments: Workon or Lsvirtualenv
    • New virtual Environment: mkvirtualenv [Virtual Environment name]
    • Start/Switch Virtual environment: Workon [Virtual Environment name]
    • Delete Virtual Environment: rmvirtualenv [Virtual Environment name]
    • Leaving the virtual environment: deactivate

Example:

Create a new virtual environment:

Mkvirtualenv Test

The terminal displays the creation process of the virtual environment, which automatically enters the virtual environment when it is created successfully:

[Email protected]:~/project/gamepf/s/init$ mkvirtualenv testnew python executableinchtest/bin/pythoninstalling setuptools, Pip ... Done. virtualenvwrapper.user_scripts Creating/home/chenxing/.virtualenvs/test/bin/predeactivatevirtualenvwrapper.user_scripts Creating/home/chenxing/.virtualenvs/test/bin/postdeactivatevirtualenvwrapper.user_scripts Creating/home/chenxing/.virtualenvs/test/bin/preactivatevirtualenvwrapper.user_scripts Creating/home/chenxing/.virtualenvs/test/bin/postactivatevirtualenvwrapper.user_scripts Creating/home/chenxing/.virtualenvs/test/bin/get_env_details (Test) [email protected]:~/project/gamepf/s/init$

You can then perform the operation of the virtual environment through the commands listed in "using" above.

Management practices:

Finally, when you build a virtual environment, you can install the packages that your projects depend on in a virtual environment, and the packages you install will be isolated from the outside development environment under the virtual environment you create. You can then write all the packages that the project depends on and the version of the package to the file by generating Requirements.txt:

    1. Write the package dependency information to the Requirements.txt:
Pip Freeze > Requirements.txt

2. You can then upload the package to the Project version management tool (SVN, git), and the server gets the code and downloads the project package via Requirements.txt:

Pip Install-r requirements.txt

Then, if there is any expansion pack installed, you can manage the development environment and the deployment environment well through steps 1th and 2nd above.

Python Environmental Management--virtualenvwrapper

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.