Skip to content

Instantly share code, notes, and snippets.

@paveu
Forked from hminnovation/zsh-virtualenv-setup.md
Created December 26, 2017 20:00
Show Gist options
  • Save paveu/e4bb73353aa952877b0f47dc2dfc9ab3 to your computer and use it in GitHub Desktop.
Save paveu/e4bb73353aa952877b0f47dc2dfc9ab3 to your computer and use it in GitHub Desktop.
ZSH Virtualenv and Virtualenvwrapper setup

### Installing global Python & Pip Use Brew brew install python

That'll install both Python, PIP and setuptools. If for some reason it didn't install PIP you can do via

curl https://bootstrap.pypa.io/get-pip.py > get-pip.py
sudo python get-pip.py

c/f MacOSX setup gitbook

(Side note that you should install multiple versions of Python via Pyenv rather than Brew to avoid any bad Python conflicts)

Installing Virtualenv & Virtualenvwrapper

pip install virtualenv virtualenvwrapper

You'll need to tell ZSH where virtualenvs need to be put

In ~/.zshrc add

# Virtualenvwrapper things
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Devel
source /usr/local/bin/virtualenvwrapper.sh

Showing the virtualenv name

By default the ZSH virtualenv plugin hides the virtualenv name. I've no idea why...

nano ~/.oh-my-zsh/plugins/virtualenv/virtualenv.plugin.zsh

Within that file you'll see

# disables prompt mangling in virtual_env/bin/activate
export VIRTUAL_ENV_DISABLE_PROMPT=1

Hash out export VIRTUAL_ENV_DISABLE_PROMPT=1 and reload ZSH.

Test that all working by doing something like

~ mkvirtualenv test2

You should see

New python executable in /Users/edd/.virtualenvs/test2/bin/python2.7
Also creating executable in /Users/edd/.virtualenvs/test2/bin/python
Installing setuptools, pip, wheel...done.
virtualenvwrapper.user_scripts creating /Users/edd/.virtualenvs/test2/bin/predeactivate
virtualenvwrapper.user_scripts creating /Users/edd/.virtualenvs/test2/bin/postdeactivate
virtualenvwrapper.user_scripts creating /Users/edd/.virtualenvs/test2/bin/preactivate
virtualenvwrapper.user_scripts creating /Users/edd/.virtualenvs/test2/bin/postactivate
virtualenvwrapper.user_scripts creating /Users/edd/.virtualenvs/test2/bin/get_env_details
(test2) ➜  ~ pip install something_awesome_inside_my_obvious_virtualenv 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment