Skip to content

Instantly share code, notes, and snippets.

@samkeen
Last active October 1, 2015 15:22
Show Gist options
  • Save samkeen/e6f07969ab04106331fb to your computer and use it in GitHub Desktop.
Save samkeen/e6f07969ab04106331fb to your computer and use it in GitHub Desktop.
My OSX Python env setup

Python Dev machine setup

WORK IN PROGRESS

Documenting my specific tweaks here. I feel this doc does a great job of covering the basics of virtualenv and virtualenvwrapper.

brew update
brew install python
brew install python3
pip install virtualenv
pip install virtualenvwrapper

edit ~/.bashr_profile

#file: ~/.bashrc
# pip should only run if there is a virtualenv currently activated
export PIP_REQUIRE_VIRTUALENV=true

## TMP
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Projects/python
source /usr/local/bin/virtualenvwrapper.sh
## END TMP

New Project

New virtual environment using Python 3

mkvirtualenv --python=$(which python3) MyProjectEnv

This creates a folder MyProjectEnv inside the environments folder ~/.virtualenvs.
The new environment will be active after running the previous command. To deactivate it, just type:

$ deactivate

and to activate it again

workon MyProjectEnv

While being in your python3 virtual envirnoment, if you type

$ python

you activate python 3! Moreover, you can use pip to call pip3 and install python3 packages.

Freezing

In order to keep your environment consistent, it's a good idea to "freeze" the current state of the environment packages. To do this, run

$ pip freeze > requirements.txt

This will create a requirements.txt file, which contains a simple list of all the packages in the current environment, and their respective versions. Later it will be easier for a different developer (or you, if you need to re-create the environment) to install the same packages using the same versions:

$ pip install -r requirements.txt

Links

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment