b.splendous.net

python virtualenv setup steps

June 2017 / tech

This is as much for my information as for anyone else's. I don't start Python projects often enough to have this wired in, so rather than search the internet every time here I go:

mkdir $mynewproject
cd $mynewproject

virtualenv venv-$mynewproject
source venv-$mynewproject/bin/activate

git init .
cat > .gitignore << EEOF
venv-$mynewproject/**
*.pyc
*.swp
EEOF

git add .gitignore

pip freeze > requirements.txt

To do work from a clean shell:

cd $mynewproject
source venv-$mynewproject/bin/activate

To do work in a new clone:

git clone $mynewproject $foo
cd $foo

virtualenv venv-$mynewproject
source venv-$mynewproject/bin/activate
pip install -r requirements.txt

Sources: