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
List Virtual environments:
$ lsvirtualenv-benv1env2
To switch between virtual environments:
$ Workon ENV1
See which packages are installed in your environment:
$ lssitepackages
Enter the current environment:
$ cdvirtualenv
Site-packages into the current environment:
$ cdsitepackages$ cdsitepackages pip
To replicate a virtual environment:
$ cpvirtualenv env1 env3copying env1 as Env3 ...
Exit the virtual Environment:
$ deactivate
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