Top Banner
Pip, Virtualenv, VirtualenvWrapper & More Django District Wednesday, Nov. 7, 2012 Jackie Kazil @jackiekazil
23

Django district pip, virtualenv, virtualenv wrapper & more

May 08, 2015

Download

Technology

Jackie Kazil

Quick intro of pip, virtualenv, virtualenv wrapper, followed by a current ways to extend and add on.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Django district  pip, virtualenv, virtualenv wrapper & more

Pip, Virtualenv, VirtualenvWrapper &

MoreDjango District

Wednesday, Nov. 7, 2012

Jackie Kazil@jackiekazil

Page 2: Django district  pip, virtualenv, virtualenv wrapper & more

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

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

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

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

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

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

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

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

What is virtualenvwrapper?

Helps make things easier...

workon foo vs

source ~/.virtualenvs/foo/bin/activate

Page 11: Django district  pip, virtualenv, virtualenv wrapper & more

Installing libraries

pip install djangopip install -r requirements.txtpip install -U django

Page 12: Django district  pip, virtualenv, virtualenv wrapper & more

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

Wrappers

● mkvirtualenv (calls hooks)● rmvirtualenv● workon (calls hooks)● add2virtualenv● cdsitepackages● cdvirtualenv● deactivate (calls hooks)

Page 14: Django district  pip, virtualenv, virtualenv wrapper & more

Hooks

● postmkvirtualenv● prermvirtualenv● postrmvirtualenv● postactivate● predeactivate● postdeactivate

Page 15: Django district  pip, virtualenv, virtualenv wrapper & more

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

Hooks example: postmkvirtualenv

https://gist.github.com/4034103

Page 17: Django district  pip, virtualenv, virtualenv wrapper & more

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

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

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

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

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

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

The End

Me: Jackie Kazil, @jackiekazil

W/ contributions from... Chris Adams, @acdha

&Members of Django-District :-)http://www.django-district.org/