Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Python environments

2,669 views

Published on

Epically winning at Python!

Published in: Technology
  • Be the first to comment

Python environments

  1. 1. PythonEnvironments! Epically winning at Python! Glen Zangirolami Twitter @glenbot http://theglenbot.comPrepared for the 100th PyHou meetup.
  2. 2. Environments! Porque?
  3. 3. Environments! Porque?Isolation - Python packages and even versions live intheir own little $HOME!
  4. 4. Environments! Porque?Isolation - Python packages and even versions live intheir own little $HOME!Permissions - Not everyone is 1337 and can be a sudoer.
  5. 5. Environments! Porque?Isolation - Python packages and even versions live intheir own little $HOME!Permissions - Not everyone is 1337 and can be a sudoer.Organization - each project can maintain it’s ownrequirements file of python packages and you don’thave version overlap.
  6. 6. Environments! Porque?Isolation - Python packages and even versions live intheir own little $HOME!Permissions - Not everyone is 1337 and can be a sudoer.Organization - each project can maintain it’s ownrequirements file of python packages and you don’thave version overlap.Anti-globalization - installing stuff to the systemglobally is generally not a good idea, unless it’ssomething like PIP.
  7. 7. Ok fine. But how?
  8. 8. Ok fine. But how?virtualenv http://pypi.python.org/pypi/virtualenvvirtualenvwrapper http://www.doughellmann.com/projects/ virtualenvwrapper/pythonbrew https://github.com/utahta/pythonbrew
  9. 9. virtualenv
  10. 10. virtualenv$ easy_install pip$ pip install virtualenv$ virtualenv <ENV>
  11. 11. virtualenv$ easy_install pip$ pip install virtualenv$ virtualenv <ENV>This creates a folder <ENV> in the $PWD.<ENV>/lib/pythonX.X/site-packages
  12. 12. virtualenvwrapper
  13. 13. virtualenvwrapper$ pip install virtualenvwrapper
  14. 14. virtualenvwrapper$ pip install virtualenvwrapperSome simple environment vars need to go into .bashrcexport WORKON_HOME=$HOME/.virtualenvsource /usr/local/bin/virtualenvwrapper.shexport PIP_VIRTUALENV_BASE=$WORKON_HOMEexport PIP_RESPECT_VIRTUALENV=true
  15. 15. virtualenvwrapper $ pip install virtualenvwrapper Some simple environment vars need to go into .bashrc export WORKON_HOME=$HOME/.virtualenv source /usr/local/bin/virtualenvwrapper.sh export PIP_VIRTUALENV_BASE=$WORKON_HOME export PIP_RESPECT_VIRTUALENV=trueThe last package that you should ever install globally
  16. 16. virtualenv + virtualenvwrapper =
  17. 17. virtualenv + virtualenvwrapper = Can you guess it?
  18. 18. virtualenv + virtualenvwrapper = Can you guess it?
  19. 19. 1up - pythonbrew
  20. 20. 1up - pythonbrew$ curl -kL http://xrl.us/pythonbrewinstall | bash
  21. 21. 1up - pythonbrew$ curl -kL http://xrl.us/pythonbrewinstall | bashSome simple code needs to go into .bashrc[[ -s $HOME/.pythonbrew/etc/bashrc ]] && source$HOME/.pythonbrew/etc/bashrc
  22. 22. virtualenv + virtualenvwrapper + pythonbrew =
  23. 23. virtualenv + virtualenvwrapper + pythonbrew = Can you guess it?
  24. 24. virtualenv + virtualenvwrapper + pythonbrew = Can you guess it?
  25. 25. Using virtualenvwrapper$ mkvirtualenv python-rules$ workon python-rules$ pip install pygett$ deactivate$ cdsitepackages$ lssitepackages$ rmvirtualenv python-rules
  26. 26. Using pythonbrew$ pybrew list$ pybrew install --force 2.7.2$ pybrew switch 2.7.2$ pybrew install --force 2.4.6$ pybrew switch 2.4.6$ pybrew venv create -p 2.7.2 python-rules$ pybrew off$ pybrew py awesome_script.py
  27. 27. Holy grail ofpythonbrew
  28. 28. Holy grail ofpythonbrewAre you ready for this?
  29. 29. Holy grail of pythonbrew Are you ready for this?Ok, maybe it’s not THAT epic ;)
  30. 30. Holy grail of pythonbrew Are you ready for this? Ok, maybe it’s not THAT epic ;)$ pybrew py awesome_script.py
  31. 31. Holy grail of pythonbrew Are you ready for this? Ok, maybe it’s not THAT epic ;) $ pybrew py awesome_script.pyWhat does this do?!?! It tests your python script against all python versions! EPIC!
  32. 32. Let’s reiterate
  33. 33. Let’s reiteratevirtualenv & virtualenvwrapper allow you tocreate environments and manage them withthe default system Python.
  34. 34. Let’s reiteratevirtualenv & virtualenvwrapper allow you tocreate environments and manage them withthe default system Python.pybrew is like virtualenv & virtualenvwrapperhad babies with a BRAWNDO ENERGYDRINK! WIN AT PYTHON!
  35. 35. The EPIC end. Thanks for listening.I’m Glen Zangirolami and I love developing EPIC Python projects that WIN. Twitter @glenbot http://theglenbot.com

×