Virtualenv Quick Start Guide

Source: Internet
Author: User
Tags virtual environment virtualenv

Virtualenv Quick Start Guide
1. virtualenv Overview

virtualenvCreate an independent Python development environment tool to solve the dependency, version, and indirect permission issues. For example, if a project depends on Django1.3 and the current global development environment is Django1.7 and the version span is too large, the project cannot be running due to incompatibility. Using virtualenv can solve these problems.

virtualenvCreate an environment with its own installation directory. This environment does not share libraries with other virtual environments, allowing you to conveniently manage python versions and python libraries.

2. Install Virtualenv

UsepipInstall Virtualenv

$ Pip install virtualenv $ sudo pip install virtualenv # Or use sudo to temporarily escalate permissions due to permission issues
3. virtualenv uses 3.1 to create a python environment using virtualenv
$ Virtualenv test # create a directory named test, install bin/python and bin/pip, and create lib, include, bin directory Using base prefix'/usr' New python executable in/home/zhangchengfei/test/bin/python3 Also creating executable in/home/zhangchengfei/test/bin/python Installing setuptools, pip, wheel... done. $ cd test $ ll drwxrwxr-x 2 contains zhangchengfei 4096 May 24 19:37 bin/drwxrwxr-x 2 contains records 4096 May 24 19:37 include/drwxrwxr-x 3 zhangchengfei 4096 May 24 19:37 lib/-rw -rw-r -- 1 zhangchengfei 60 May 24 19:37 pip-selfcheck.json
  • libAll installed python libraries will be placed under lib/pythonx. x/site-packages/in this directory.
  • bin, Bin/python is the python interpreter used in the current environment

If you runvirtualenv --system-site-packages test, Will inherit/usr/lib/python2.7/site-packagesThe latest version of virtualenv takes the access to the global site-packages as the default action.

3.2 activate virtualenv
  • Run the following command in the test directory:

    $ Source./bin/activate # activate the current virtualenv (test) $ # note that the terminal has changed
  • UsepipView the current library, display dependencies, and generate the requirement File

    (Test) $ pip listpip (8.1.2) setuptools (21.2.1) wheel (0.29.0) # currently only the three pip freeze # Show All dependent pip freeze> requirement.txt # generate the requirement.txt file pip install-r requirement.txt # generate requirement.txt to generate the same environment
3.3 disable virtualenv
  • Use the following command

    $ deactivate
3.4 specify the python version
  • Available-p PYTHON_EXESpecifies the python version when creating a virtual environment.

    # Create a python2.7 Virtual Environment $ virtualenv-p/usr/bin/python2.7 test Running virtualenv with interpreter/usr/bin/python2.7 New python executable in/home/tests/test/bin/python2.7 not overwriting existing python script/home/zhangchengfei/test/bin/python (you must use/home/zhangchengfei/test/bin/python2.7) installing setuptools, pip, wheel... done. # create a python3.4 Virtual Environment $ virtualenv-p/usr/local/bin/python3.4 test Running virtualenv with interpreter/usr/bin/python3.4 Using base prefix'/usr 'new python executable in/ home/zhangchengfei/test/bin/python3.4 Also creating executable in/home/zhangchengfei/test/bin/python Installing setuptools, pip, wheel... done.
4. Generate a packable Environment
  • In some special requirements, there may be no network. We hope to package a test directly, which can be decompressed and used directly at this time.virtualenv -relocatableCommand to change test to a test

    # Change the created virtual environment to [test] $ virtualenv -- relocatable for migration. /Making script/home/zhangchengfei/test/bin/wheel relative Making script/home/zhangchengfei/test/bin/pip3 relative Making script/home/zhangchengfei/test/bin/pip relative making script/home/zhangchengfei/test/bin/easy_install-3.4 relative Making script/home/zhangchengfei/test/bin/pip3.4 relative Making script/home/zhangchengfei/test/bin/python-config relative Making script/home/zhangchengfei/test/bin/easy_install relative

[End]

Virtualenv create a virtual environment to install Flask

Python virtual environment: Virtualenv

Use Virtualenv in CentOS6.5 to build the Python3 Development Environment

This article permanently updates the link address:

Related Article

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.