Mac Configuration Virtual Environment virtualenv

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

Recently, I was learning python to do scientific calculations, of course, in many books and public classes The first thing to do is to install NumPy, Scipy, matplotlib and other packages, but each time you install a separate package, there will be a variety of problems caused Installation FailedOr call failed


Like what
Encounter Exception and Error:


Sklearn has been prompted to install successfully, but the call is displayed:
ImportError: No module named sklearn

Also useful for Numpy:
ValueError: numpy.dtype has the wrong size, try recompiling

See everyone said that with the virtual environment is better, I also own a, sure enough in the virtualenv on the installation of various packages are very smooth, with very smooth, there is no problem.

Virtualenv can be used to build a python environment that belongs to the project, maintaining a clean environment. Only need to create a virtual environment through the command, without the time by the command to quit, delete.

Here are the installation methods:

    • Installing Virtualenv

    • Installing Virtualenvwrapper

    • Installation Numpy,scipy,matplotlib, etc.

Installing Virtualenv
$ sudo pip install virtualenv

Then create a test directory:

$ mkdir testvirtual$ CD testvirtual

You can successfully create a virtual environment ENV1:

$ virtualenv ENV1
Installing Virtualenvwrapper

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

Run the following command to install successfully, the default installation is as /usr/local/bin follows:

$ sudo easy_install virtualenvwrapper

Next, create a folder to hold all the virtual environments:

$ mkdir ~/workspaces$ CD ~/workspaces

But before using the Virtualenvwrapper, to run the virtualenvwrapper.sh file, you need to set the environment variables, that is, the following two lines of code in ~/.bashrc , but my computer did not ~/.bashrc , check the solution, For example, you create a BASHRC to write in two lines of code, also no use.

export WORKON_HOME=~/workspaces
source /usr/bin/virtualenvwrapper.sh

The last option is to write directly at the command line and succeed:

$ Export workon_home=~/workspaces$ source/usr/local/bin/virtualenvwrapper.sh

Next, create one or more virtual environments Env1,env2:

$ mkvirtualenv ENV1

Once successful, the current path will be preceded by a(env1)

$ mkvirtualenv Env2

Here are some basic operations commands

    1. List Virtual environments:

$ lsvirtualenv-benv1env2
    1. To switch between virtual environments:

$ Workon ENV1
    1. See which packages are installed in your environment:

$ lssitepackages
    1. Enter the current environment:

$ cdvirtualenv
    1. Site-packages into the current environment:

$ cdsitepackages$ cdsitepackages pip
    1. To replicate a virtual environment:

$ cpvirtualenv env1 env3copying env1 as Env3 ...
    1. Exit the virtual Environment:

$ deactivate
    1. To delete a virtual environment:

$ rmvirtualenv env2removing env2 ...
Installation Numpy,scipy,matplotlib, etc.

Following the installation of Python's various packages, it is more smooth, such as Ann on the ENV1:

$ Workon ENV1

Installing NumPy
pip install numpy

Installing scipy
$ pip install scipy

Installing Matplotlib
$ pip install matplotlib

Installing Ipython
$ pip install ipython[all]

Installing Pandas
$ pip install pandas

Installing Statsmodel
$ pip install statsmodel

Installing Scikit-learn
$ pip install scikit-learn

In order to complete the installation successfully, follow-up can be analyzed in the virtual environment.

Each time you enter the virtual environment, the following code can be executed,
However, because my environment variables are not written into the BASHRC, we have to execute two more lines:

$ cd ~/workspaces$ export workon_home=~/workspaces$ source/usr/local/bin/virtualenvwrapper.sh$ WORKON ENV1

Exiting the virtual environment is used

$ deactivate

Originated from HTTPS://WWW.JIANSHU.COM/P/51140800E8B4

Mac Configuration Virtual Environment virtualenv

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.