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
You can successfully create another virtual environment env2:
$ virtualenv env2
然后想进入哪个虚拟环境就CD进去就可以了,比如进入env1:
$ cd env1
安装 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:
Next, create a folder to hold all the virtual environments:
cd ~/workspaces
先用
which virtualenvwrapper.sh
which python3
这个命令找到正确路径
然后用
VI ~/.bash_profile ENTER
Input
Export workon_home= ' ~/.virtualenvs '
Export virtualenvwrapper_python= '/users/mac/anaconda/bin/python3 '
source/users/mac/anaconda/bin/virtualenvwrapper.sh
After ESC exits: Wq to save
Run this command again source ~/.bash_profile
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:
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
Build a Python virtual environment on your Mac