django district pip, virtualenv, virtualenv wrapper & more
DESCRIPTION
Quick intro of pip, virtualenv, virtualenv wrapper, followed by a current ways to extend and add on.TRANSCRIPT
![Page 1: Django district pip, virtualenv, virtualenv wrapper & more](https://reader034.vdocuments.mx/reader034/viewer/2022051400/554bc065b4c9053a298b50af/html5/thumbnails/1.jpg)
Pip, Virtualenv, VirtualenvWrapper &
MoreDjango District
Wednesday, Nov. 7, 2012
Jackie Kazil@jackiekazil
![Page 2: Django district pip, virtualenv, virtualenv wrapper & more](https://reader034.vdocuments.mx/reader034/viewer/2022051400/554bc065b4c9053a298b50af/html5/thumbnails/2.jpg)
Where we all start
● easy_install Globally● And it works! Yay!● But then....
○ dependencies or versions○ coordination w/ other developers○ keeping different systems on same page○ breaking sys python
![Page 3: Django district pip, virtualenv, virtualenv wrapper & more](https://reader034.vdocuments.mx/reader034/viewer/2022051400/554bc065b4c9053a298b50af/html5/thumbnails/3.jpg)
Case study: Dependencies
Once upon a time in city, much like this one, there was a newspaper...
….. over 90 Django applications updated from 0.96 to 1.1.
![Page 4: Django district pip, virtualenv, virtualenv wrapper & more](https://reader034.vdocuments.mx/reader034/viewer/2022051400/554bc065b4c9053a298b50af/html5/thumbnails/4.jpg)
Case study: Breaking sys python
From stackoverflow... "Is there a way to ensure I can clean everything up and start from zero?"
"If you remove everything in these 2 directories, it should clear out all modules...."
![Page 5: Django district pip, virtualenv, virtualenv wrapper & more](https://reader034.vdocuments.mx/reader034/viewer/2022051400/554bc065b4c9053a298b50af/html5/thumbnails/5.jpg)
Why Pip & Virtualenv
● Isolate○ System packages from project packages○ Projects from each other
● No sudo required - sys python requires sudo access, project python doesn’t
![Page 6: Django district pip, virtualenv, virtualenv wrapper & more](https://reader034.vdocuments.mx/reader034/viewer/2022051400/554bc065b4c9053a298b50af/html5/thumbnails/6.jpg)
Becoming the standard...
Pep 405Python 3.3
http://www.python.org/dev/peps/pep-0405
"... proposes to add to Python a mechanism for lightweight "virtual environments" with their own site directories, optionally isolated from system site directories...."
![Page 7: Django district pip, virtualenv, virtualenv wrapper & more](https://reader034.vdocuments.mx/reader034/viewer/2022051400/554bc065b4c9053a298b50af/html5/thumbnails/7.jpg)
What is...
● pip - replaces easy_install
● virtualenv - creates isolated python environments
● virtualenvwrapper - to be explained later
![Page 8: Django district pip, virtualenv, virtualenv wrapper & more](https://reader034.vdocuments.mx/reader034/viewer/2022051400/554bc065b4c9053a298b50af/html5/thumbnails/8.jpg)
Basic setup
$ sudo easy_install pip$ sudo pip install virtualenv$ sudo pip install virtualenvwrapper
Add to bash settings... source /usr/local/bin/virtualenvwrapper.shexport WORKON_HOME=$HOME/.virtualenvs
![Page 9: Django district pip, virtualenv, virtualenv wrapper & more](https://reader034.vdocuments.mx/reader034/viewer/2022051400/554bc065b4c9053a298b50af/html5/thumbnails/9.jpg)
Make environment
$ mkvirtualenv foo
You can add more to this... like setting python version.$ mkvirtualenv --python=python2.7
![Page 10: Django district pip, virtualenv, virtualenv wrapper & more](https://reader034.vdocuments.mx/reader034/viewer/2022051400/554bc065b4c9053a298b50af/html5/thumbnails/10.jpg)
What is virtualenvwrapper?
Helps make things easier...
workon foo vs
source ~/.virtualenvs/foo/bin/activate
![Page 11: Django district pip, virtualenv, virtualenv wrapper & more](https://reader034.vdocuments.mx/reader034/viewer/2022051400/554bc065b4c9053a298b50af/html5/thumbnails/11.jpg)
Installing libraries
pip install djangopip install -r requirements.txtpip install -U django
![Page 12: Django district pip, virtualenv, virtualenv wrapper & more](https://reader034.vdocuments.mx/reader034/viewer/2022051400/554bc065b4c9053a298b50af/html5/thumbnails/12.jpg)
Where does it live? ~/.virtualenv/foo/...
…/binBinaries in your env. Example: ipython
.../includeDev headers used by the #include directive in C.
…/libWhere all your python libraries will livelib/python2.7/site-packages
.../shareMans & Docs
![Page 13: Django district pip, virtualenv, virtualenv wrapper & more](https://reader034.vdocuments.mx/reader034/viewer/2022051400/554bc065b4c9053a298b50af/html5/thumbnails/13.jpg)
Wrappers
● mkvirtualenv (calls hooks)● rmvirtualenv● workon (calls hooks)● add2virtualenv● cdsitepackages● cdvirtualenv● deactivate (calls hooks)
![Page 14: Django district pip, virtualenv, virtualenv wrapper & more](https://reader034.vdocuments.mx/reader034/viewer/2022051400/554bc065b4c9053a298b50af/html5/thumbnails/14.jpg)
Hooks
● postmkvirtualenv● prermvirtualenv● postrmvirtualenv● postactivate● predeactivate● postdeactivate
![Page 15: Django district pip, virtualenv, virtualenv wrapper & more](https://reader034.vdocuments.mx/reader034/viewer/2022051400/554bc065b4c9053a298b50af/html5/thumbnails/15.jpg)
Hook example: postactivate
proj_name=$(echo $VIRTUAL_ENV|awk -F'/' '{print $NF}')
if [ $proj_name = "foo" ]; then cd /opt/foo/core/ export DJANGO_SETTINGS_MODULE='settings.dev_settings' echo "DJANGO_SETTINGS_MODULE set to:" $DJANGO_SETTINGS_MODULEfi
![Page 16: Django district pip, virtualenv, virtualenv wrapper & more](https://reader034.vdocuments.mx/reader034/viewer/2022051400/554bc065b4c9053a298b50af/html5/thumbnails/16.jpg)
Hooks example: postmkvirtualenv
https://gist.github.com/4034103
![Page 17: Django district pip, virtualenv, virtualenv wrapper & more](https://reader034.vdocuments.mx/reader034/viewer/2022051400/554bc065b4c9053a298b50af/html5/thumbnails/17.jpg)
Other helpful stuff
pip freezepip freeze > requirements.txt
yolk -l
python -c "import sys,pprint;pprint.pprint(sys.path)"
![Page 18: Django district pip, virtualenv, virtualenv wrapper & more](https://reader034.vdocuments.mx/reader034/viewer/2022051400/554bc065b4c9053a298b50af/html5/thumbnails/18.jpg)
More... virtualenv-burrito
https://github.com/brainsik/virtualenv-burrito
With one command.... BAM! (or maybe not)... a virtualenv & virtualenvwrapper environment
![Page 19: Django district pip, virtualenv, virtualenv wrapper & more](https://reader034.vdocuments.mx/reader034/viewer/2022051400/554bc065b4c9053a298b50af/html5/thumbnails/19.jpg)
More... virtualenv-tools
https://github.com/fireteam/virtualenv-tools
"This repository contains scripts we're using at Fireteam for our deployment of Python code."
![Page 20: Django district pip, virtualenv, virtualenv wrapper & more](https://reader034.vdocuments.mx/reader034/viewer/2022051400/554bc065b4c9053a298b50af/html5/thumbnails/20.jpg)
More... Tox http://tox.testrun.org/latest/
Tox as is a generic virtualenv management and test command line tool you can use for:● checking your package installs correctly with different
Python versions and interpreters
● running your tests in each of the environments, configuring your test tool of choice
● acting as a frontend to Continuous Integration servers, greatly reducing boilerplate and merging CI and shell-based testing.
![Page 21: Django district pip, virtualenv, virtualenv wrapper & more](https://reader034.vdocuments.mx/reader034/viewer/2022051400/554bc065b4c9053a298b50af/html5/thumbnails/21.jpg)
More .... Keeping things fresh
Autoenvhttps://github.com/kennethreitz/autoenv"Magic per-project shell environments. Very pretentious."
Bundle Scouthttp://bundlescout.com/"Daily emails keep you on top of the latest updates from your favorite libraries."
![Page 22: Django district pip, virtualenv, virtualenv wrapper & more](https://reader034.vdocuments.mx/reader034/viewer/2022051400/554bc065b4c9053a298b50af/html5/thumbnails/22.jpg)
More .... Keeping things fresh (cont)
Pip Linthttps://github.com/dcramer/piplint"Piplint validates your current environment with the requirements files you've specified."
Pip Toolshttps://github.com/nvie/pip-tools"A set of two command line tools to help you keep your pip-based packages fresh, even when you've pinned them"
![Page 23: Django district pip, virtualenv, virtualenv wrapper & more](https://reader034.vdocuments.mx/reader034/viewer/2022051400/554bc065b4c9053a298b50af/html5/thumbnails/23.jpg)
The End
Me: Jackie Kazil, @jackiekazil
W/ contributions from... Chris Adams, @acdha
&Members of Django-District :-)http://www.django-district.org/