Install Virtualenv And Virtualenvwrapper On Mac Os X
Install virtualenv and virtualenvwrapper on Mac OS X
Akbar S. Ahmed | Feb 10, 2015

Step-by-step instructions

virtualenv is an absolute must if you develop with Python. In simple terms, virtualenv creates a folder that stores a private copy of python, pip, and other Python packages. You can then enable this private folder while working a project. By using the virtual environment, you can use different versions of Python and Python packages on a per project basis.

In this post we will step through setting up virtualenv and virtualenvwrapper on Mac OS X.

Prerequisites

The preinstalled version of Python on Mac OS X is not ideal for development. Therefore, you should install a version of Python that is better suited for development.

Step-by-step instructions

Open a terminal and install the following packages.

pip install virtualenv virtualenvwrapper

Setup virtualenvwrapper in ~/.bash_profile.

# Create a backup of your .bash_profile
cp ~/.bash_profile ~/.bash_profile-org

# Be careful with this command
printf '\n%s\n%s\n%s' '# virtualenv' 'export WORKON_HOME=~/virtualenvs' \
'source /usr/local/bin/virtualenvwrapper.sh' >> ~/.bash_profile

Enable the virtual environment.

source ~/.bash_profile

mkdir -p $WORKON_HOME

mkvirtualenv api

# Exit the 'api' virtual environment
deactivate

Tips on using virtualenv

To enable the api virtual environment, run the following command:

workon api

To deactivate the api virtual environment, run the following command:

deactivate

That’s it. You now have a virtual environment setup for your Python development.




Subscribe to our newsletter

Contact Information

ABOUT EXPONENTIAL.IO

We specialize in helping professional developers, like you, expand your skill set. Our courses are focused on enabling you to learn everything necessary to use a new technology in a live, production application.

LOCATION

All courses are made with love in
Palo Alto, CA.

Subscribe to our newsletter