Use VIRTUALENV to build virtual environment on Mac

Source: Internet
Author: User
Tags virtual environment virtualenv install pandas install matplotlib


You can install the "sudo pip install package name" during the development process if you want to install the Python package.

Different versions of the same package are used when developing different projects, and the installation with the above command will cause other items to run (overwritten).


Virtual Environment

A virtual environment can build a separate Python run environment that will not affect a single project's operating environment and other project-running environments.

Here's how to install this:

1. Install virtualenv----sudo pip install virtualenv


$ mkdir testvirtualenv

$ CD Testvirtualenv

$ virtualenv ENV1------You can successfully create a virtual environment ENV1

2. Install virtualenvwrapper-----sudo easy_install virtualenvwrapper (I use PIP without successful installation, so use of Easy_install)

Virtualenvwrapper is a virtualenv expansion pack that makes it easier to add, remove, copy, and switch virtual environments.

3. Install virtualenvwrapper use need to configure the environment variables directly to the following two lines to write ~/.bash_profile file:

Export Workon_home= ' ~/workspace ' # #这个目录为创建虚拟环境是所在的目录, you can specify your own directory

Executes the source ~/.bash_profile command after configuring the environment variable, otherwise it does not take effect

4. To test, create two virtual environments Env1, env2

$ mkvirtualenv env1 (Create Virtual Environment ENV1)

After the creation is successful, there will be (ENV1) before the current path

$mkvirtualenv env2 (Create a virtual environment env2)

here are some common basic commands

1. Exit the current virtual environment


2. List of Virtual environments




3. Switch Virtual Environment

$workon env2

4. Enter the current virtual environment


5. Delete Virtual Environment

$rmvirtualenv ENV1

6. Site-packages into the current environment


7. See which packages are installed in your environment


8. Replicating a virtual environment

$cpvirtualenv ENV1 Env3

Let's try to install some packages (install packages in a virtual environment without sudo)

$workon ENV1

$pip Install NumPy

$pip Install SciPy

$pip Install Matplotlib

$ pip Install Ipython

$pip Install Pandas

$pip Install Scikit-learn

Execute lssitepackages to see how many packages have been installed in the ENV1

Workon env2 Switch to Env2

$lssitepackages can see that there are no packages in the env2 that were just installed in ENV1.

That's it. Different environments do not affect each other and do not harm ^_^

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: 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.