Python installs virtual environments in Linux, differentiating between Python2 and Python3, installing modules separately

Source: Internet
Author: User

Install the virtual environment when the problem encountered, the process is very disturbing, here simple and direct sharing, is to solve the problem.

Install the virtual environment (must be in the networked state)

$ sudo pip install virtualenv$ sudo pip install virtualenvwrapper

After installing the virtual environment, if you are prompted to not find the mkvirtualenv command, you must configure the environment variable:

# 1、创建目录用来存放虚拟环境mkdir $HOME/.virtualenvs# 2、打开~/.bashrc文件,并添加如下:export WORKON_HOME=$HOME/.virtualenvssource /usr/local/bin/virtualenvwrapper.sh# 3、运行source ~/.bashrc

Create a virtual environment (Ubuntu must define its own environment name in the networked state)

$ mkvirtualenv scrapy -p python3    # python3虚拟环境
Flask    # python2虚拟环境

Enter the appropriate virtual environment and use PIP to install the Python module

$ workon Flask

Exiting a virtual environment

If your environment is a real environment, you will be prompted deactivate: command not found

$ deactivate Flask

Deleting a virtual environment

If your environment is a real environment, you will be prompted deactivate: command not found

$ rmvirtualenv Flask


总结:以上是简单的安装python3和python2的虚拟环境,命令可以直接用,按自己的需要修改虚拟环境名字即可

Python installs virtual environments in Linux, differentiating between Python2 and Python3, installing modules separately

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.