Build a Python virtual environment on your Mac

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

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

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

Build a Python virtual environment on your Mac

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.