Installing a Python virtual environment

Source: Internet
Author: User
Tags virtual environment

Virtual environments:

command to install Python package before: sudo pip3 install package name
Installation path of the package:/usr/local/lib/python3.5/dist-packages
Install different versions of the same package, and the packages that are installed will overwrite the packages that were originally installed. Thus, as two projects on a machine depend on different versions of the same package, some projects will fail to run.
The solution is: virtual Environments.
A virtual environment is a replicated version of a real Python environment.

To install a virtual Environment command: 

  1. sudo pip install virtualenv #安装虚拟环境

2. sudo pip install virtualenvwrapper #安装虚拟环境扩展包

3. Edit the. bashrc file under the home directory and add the following two lines.

I. Export Workon_home= $HOME/.virtualenvs
II. source/usr/local/bin/virtualenvwrapper.sh

4. Use source. BASHRC to make it effective.

To Create a Virtual Environment command:

  MKVIRTUALENV Virtual Environment name //default is Python2

To create a PYTHON3 virtual environment:

  Mkvirtualenv-p Python3 Virtual Environment name

After entering the virtual environment: enter python to view the Python version

See how many virtual environments are on the machine:

  Workon Space + two TAB key

Working in a virtual environment:

  Workon Virtual Environment Name

The commands to exit the virtual environment are as follows:

  Deactivate

To delete a variable environment: 

RMVIRTUALENV Virtual Environment Name

Exit First: Deactivate

Again Delete: Rmvirtualenv py_djan3

commands for installing packages in a virtual environment:

Pip Install package name
    Note: You cannot use the sudo pip install package name, this command installs the package to the real host environment rather than to the virtual environment.

To see which packages are installed in the virtual environment:

Method One: Pip list
Method Two: Pip freeze

  

  

Installing a Python virtual environment

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.