Virtualenv on El Capitan

In switching to a new Mac recently I needed to set up my Python and other development environments anew. Here is the quickest way I found to get a Django development environment up and running quickly on El Capitan.

First, we’ll use Homebrew to get a workable Python environment. Just go to the homebrew website and follow the instructions for installation.

Then install python:

brew install python

Note that if you want to also run python3 alongside python2 you can run “brew install python3”. This makes it easy to test your application in both python2 and python3.

Since we used Homebrew to install python you no longer need to ever use sudo in any pip commands again. If you read you need to use sudo somewhere it’s old and not needed. Don’t do it unless you want to mess your mac up.

Let’s use pip to install virtualenv.

pip install virtualenv

Last, I really like to install virtualenvwrapper because it makes working with virtualenv’s so much easier.

pip install virtualenvwrapper

We need to add virtualenvwrapper to our path so edit your ~/.bash_profile file and add the following lines.

export PATH=/usr/local/bin:$PATH
export WORKON_HOME=~/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh

Now let’s create a virtual environment

mkvirtualenv myenvname

That’s it. You’ll be switched to your virtualenv and be ready to install django or whatever package you want. When coming back to your shell you can simply type “workon myenvname” to activate the virtualenv again.

Last, if you’re working with Postgres the fantastic Postgres App is the fastest way to get setup that I’ve found. Don’t forget to run “pip install psycopg2” with your virtualenv active to be able to connect to postgres when your development server is running.

That’s it. Happy coding!

comments powered by Disqus