SlideShare ist ein Scribd-Unternehmen logo
1 von 18
VirtualEnv and Pip
Isolated Python environments
             Ryan Blunden
   Brisbane Python Group, May 2011
Summary
• Global site-packages management
• Per project package management
• VirtualEnv creates isolated Py envs
• VirtualEnvWrapper makes things easy
• Pip to install your packages
• Next... Automate your deploys
About Me
•   Have been the Front End Tech Lead at Flight Centre

•   Interested in all things web and am a fan of the new
    RESTful back-end => thick client movement

•   Python at work for back office and Systems Admin tasks.
    Don’t get why SA’s love bash scripts so much

•   Can’t build Django apps at work so I build them for
    myself and external clients

•   I’m hardly a Python expert, but I love it!
Global Package Management
•   Starts out fine

•   Overtime, things get messy

•   Not great for development in teams (sync issues)

•   Challenges in keeping dev, stage and prod environments
    in sync

•   Sometimes you don’t even have control of the prod
    global site packages

•   Easy for things to break overtime when versions and
    dependencies not clearly set
Per Project Packages
•   Enter virtualenv, a tool for creating isolated Python
    environments

•   Better than workingenv as it doesn’t rely on
    $PYTHONPATH trickery

•   Better than virtual-python as it works on Windows
    (doesn’t rely on symlinks)

•   Any of these are better than nothing, I just think
    virtualenv does it best.

•   Version 1.6.1 supports PyPy 1.5. PyPy!
Installing virtualenv
•   sudo easy_install virtualenv, then add this to your .bashrc

•   Create a new Python environment

    •   virtualenv myproject --no-site-packages
        Don’t inherit from global site-packages directory

    •   virtualenv myproject --no-site-packages --distribute
        Uses distribute instead of setup_tools

    •   I think it’s best to ensure your new env does not inherit
        packages from your global site-packages directory

•   This is ok but to make things easier to manage, let’s use
    virtualenvwrapper (Thanks Doug Hellmann)
virtualenvwrapper
•   Organises your virtualenvs into one spot
    # Put this in your .bash_profile or .bashrc
    export WORKON_HOME=$HOME/.virtualenvs
    source /usr/local/bin/virtualenvwrapper_bashrc



•   Separates your virtualenvs from your project source

•   Nice environment event hooks for automation of
    repetitive tasks (cd project on post_activate)

•   Basically, it makes your use of virtualenv more efficient

•   Now we need the perfect package management tool for
    installing packages in our env...
VirtualEnvWrapper scripts
•   mkvirtualenv (create a new virtualenv)

•   rmvirtualenv (remove an existing virtualenv)

•   workon (change the current virtualenv)

•   add2virtualenv (add external packages in a .pth file to current
    virtualenv)

•   cdsitepackages (cd into the site-packages directory of current
    virtualenv)

•   cdvirtualenv (cd into the root of the current virtualenv)

•   deactivate (deactivate virtualenv, which calls several hooks)
Virtual EnvWrapper Hooks
•   postmkvirtualenv

•   prermvirtualenv

•   postrmvirtualenv

•   postactivate

•   predeactivate

•   postdeactivate
Introducing pip
•   Pip - Pip Installs Packages, nothing more, nothing less

•   It’s good, James Bennet explains - http://goo.gl/F9m2N

•   Great at re-producing builds of specific versions of
    packages, just remember to use versioning for each
    package.

•   Every project needs at least one requirements file
Installing packages
•   By default, searches PyPi just like easy_install

•   Can also install from:
    - tarballs containing a setup.py script
    - Editable checkouts from VCS repos
    - Editable checkouts from VCS repos with revision info

•   Can install packages from Pip bundles
Installing packages
•   Installation - sudo easy_install pip

•   Workflow
    1. Make or activate virtual env
    2. Install (and search for) packages

•   pip search
    pip install package-name (latest)
    pip install package-name==1.4.5 (specific)
    pip install package-name>=1.4.5 (at least...)

•   Install packages from requirements file
    pip install -r requirements.txt

•   Freeze current packages to produce requirements file
Terminal action!

• Finally, let’s write some code
• For those watching at home, go checkout
  Mathemtism’s excellent screen cast at
  http://goo.gl/wWkti
What about my editor?

•   Good Python editors and IDE’s should support
    virtual env

•   PyCharm does by you telling it which python
    interpreter should be used for each project, it then
    nows which site packages directory to use.
Summary

• Isolated Python environments are a must
• VirtualEnv,VirtualEnvWrapper are THE way
  to manage them
Docs

•   VirtualEnv
    http://www.virtualenv.org/en/latest/

•   VirtualEnvWrapper
    http://www.doughellmann.com/docs/virtualenvwrapper/

•   Pip
    http://www.pip-installer.org/en/latest/
References
•   Pip and VirtualEnv (Awesome!)
    http://mathematism.com/2009/07/30/presentation-pip-
    and-virtualenv/

•   Tools of the Modern Python Hacker:Virtualenv, Fabric
    and Pip
    http://www.clemesha.org/blog/modern-python-hacker-
    tools-virtualenv-fabric-pip

•   Notes on using pip and virtualenv with Django
    http://www.saltycrane.com/blog/2009/05/notes-using-pip-
    and-virtualenv-django/
Thanks!

• Ryan Blunden
  ryan.blunden@gmail.com
  @ryan_blunden

Weitere ähnliche Inhalte

Andere mochten auch

2014_07_28_Django環境安裝以及 Django Book Chapter 4: Templates
2014_07_28_Django環境安裝以及 Django Book Chapter 4: Templates2014_07_28_Django環境安裝以及 Django Book Chapter 4: Templates
2014_07_28_Django環境安裝以及 Django Book Chapter 4: TemplatesKe Wei Louis
 
Jenkins djangovillage
Jenkins djangovillageJenkins djangovillage
Jenkins djangovillageLucio Grenzi
 
Virtualenv
VirtualenvVirtualenv
VirtualenvWEBdeBS
 
Django district pip, virtualenv, virtualenv wrapper & more
Django district  pip, virtualenv, virtualenv wrapper & moreDjango district  pip, virtualenv, virtualenv wrapper & more
Django district pip, virtualenv, virtualenv wrapper & moreJacqueline Kazil
 
Python packaging and dependency resolution
Python packaging and dependency resolutionPython packaging and dependency resolution
Python packaging and dependency resolutionTatiana Al-Chueyr
 
Current State of Python Packaging
Current State of Python PackagingCurrent State of Python Packaging
Current State of Python PackagingClayton Parker
 
Using Python Packages - An Overview
Using Python Packages - An OverviewUsing Python Packages - An Overview
Using Python Packages - An OverviewDaniel Hepper
 
Function calling convention
Function calling conventionFunction calling convention
Function calling conventionYuk SeungChan
 
Django in Production
Django in ProductionDjango in Production
Django in ProductionHyun-woo Park
 
Django sharing
Django sharingDjango sharing
Django sharingTom Chen
 
Django와 flask
Django와 flaskDjango와 flask
Django와 flaskJiho Lee
 
Django, 저는 이렇게 씁니다.
Django, 저는 이렇게 씁니다.Django, 저는 이렇게 씁니다.
Django, 저는 이렇게 씁니다.Kyoung Up Jung
 
12 tips on Django Best Practices
12 tips on Django Best Practices12 tips on Django Best Practices
12 tips on Django Best PracticesDavid Arcos
 
Isolated development in python
Isolated development in pythonIsolated development in python
Isolated development in pythonAndrés J. Díaz
 

Andere mochten auch (17)

2014_07_28_Django環境安裝以及 Django Book Chapter 4: Templates
2014_07_28_Django環境安裝以及 Django Book Chapter 4: Templates2014_07_28_Django環境安裝以及 Django Book Chapter 4: Templates
2014_07_28_Django環境安裝以及 Django Book Chapter 4: Templates
 
Jenkins djangovillage
Jenkins djangovillageJenkins djangovillage
Jenkins djangovillage
 
Virtualenv
VirtualenvVirtualenv
Virtualenv
 
Django district pip, virtualenv, virtualenv wrapper & more
Django district  pip, virtualenv, virtualenv wrapper & moreDjango district  pip, virtualenv, virtualenv wrapper & more
Django district pip, virtualenv, virtualenv wrapper & more
 
Python packaging and dependency resolution
Python packaging and dependency resolutionPython packaging and dependency resolution
Python packaging and dependency resolution
 
Current State of Python Packaging
Current State of Python PackagingCurrent State of Python Packaging
Current State of Python Packaging
 
Django Deployment-in-AWS
Django Deployment-in-AWSDjango Deployment-in-AWS
Django Deployment-in-AWS
 
Using Python Packages - An Overview
Using Python Packages - An OverviewUsing Python Packages - An Overview
Using Python Packages - An Overview
 
Stack frame
Stack frameStack frame
Stack frame
 
Function calling convention
Function calling conventionFunction calling convention
Function calling convention
 
Django in Production
Django in ProductionDjango in Production
Django in Production
 
Django sharing
Django sharingDjango sharing
Django sharing
 
Django와 flask
Django와 flaskDjango와 flask
Django와 flask
 
Django, 저는 이렇게 씁니다.
Django, 저는 이렇게 씁니다.Django, 저는 이렇게 씁니다.
Django, 저는 이렇게 씁니다.
 
12 tips on Django Best Practices
12 tips on Django Best Practices12 tips on Django Best Practices
12 tips on Django Best Practices
 
Isolated development in python
Isolated development in pythonIsolated development in python
Isolated development in python
 
Django quickstart
Django quickstartDjango quickstart
Django quickstart
 

Mehr von Ryan Blunden

Container Camp Sydney 2017 Summary
Container Camp Sydney 2017 SummaryContainer Camp Sydney 2017 Summary
Container Camp Sydney 2017 SummaryRyan Blunden
 
Docker Multi-Stage Builds
Docker Multi-Stage BuildsDocker Multi-Stage Builds
Docker Multi-Stage BuildsRyan Blunden
 
Python typing module
Python typing modulePython typing module
Python typing moduleRyan Blunden
 
Transpiler’s are here to stay
Transpiler’s are here to stayTranspiler’s are here to stay
Transpiler’s are here to stayRyan Blunden
 
Promises in JavaScript with jQuery
Promises in JavaScript with jQueryPromises in JavaScript with jQuery
Promises in JavaScript with jQueryRyan Blunden
 
jQuery 1.4-1.6 Best new features
jQuery 1.4-1.6 Best new featuresjQuery 1.4-1.6 Best new features
jQuery 1.4-1.6 Best new featuresRyan Blunden
 

Mehr von Ryan Blunden (6)

Container Camp Sydney 2017 Summary
Container Camp Sydney 2017 SummaryContainer Camp Sydney 2017 Summary
Container Camp Sydney 2017 Summary
 
Docker Multi-Stage Builds
Docker Multi-Stage BuildsDocker Multi-Stage Builds
Docker Multi-Stage Builds
 
Python typing module
Python typing modulePython typing module
Python typing module
 
Transpiler’s are here to stay
Transpiler’s are here to stayTranspiler’s are here to stay
Transpiler’s are here to stay
 
Promises in JavaScript with jQuery
Promises in JavaScript with jQueryPromises in JavaScript with jQuery
Promises in JavaScript with jQuery
 
jQuery 1.4-1.6 Best new features
jQuery 1.4-1.6 Best new featuresjQuery 1.4-1.6 Best new features
jQuery 1.4-1.6 Best new features
 

Kürzlich hochgeladen

Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxcallscotland1987
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 

Kürzlich hochgeladen (20)

Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 

VirtualEnv and Pip - Isolated Python environments

  • 1. VirtualEnv and Pip Isolated Python environments Ryan Blunden Brisbane Python Group, May 2011
  • 2. Summary • Global site-packages management • Per project package management • VirtualEnv creates isolated Py envs • VirtualEnvWrapper makes things easy • Pip to install your packages • Next... Automate your deploys
  • 3. About Me • Have been the Front End Tech Lead at Flight Centre • Interested in all things web and am a fan of the new RESTful back-end => thick client movement • Python at work for back office and Systems Admin tasks. Don’t get why SA’s love bash scripts so much • Can’t build Django apps at work so I build them for myself and external clients • I’m hardly a Python expert, but I love it!
  • 4. Global Package Management • Starts out fine • Overtime, things get messy • Not great for development in teams (sync issues) • Challenges in keeping dev, stage and prod environments in sync • Sometimes you don’t even have control of the prod global site packages • Easy for things to break overtime when versions and dependencies not clearly set
  • 5. Per Project Packages • Enter virtualenv, a tool for creating isolated Python environments • Better than workingenv as it doesn’t rely on $PYTHONPATH trickery • Better than virtual-python as it works on Windows (doesn’t rely on symlinks) • Any of these are better than nothing, I just think virtualenv does it best. • Version 1.6.1 supports PyPy 1.5. PyPy!
  • 6. Installing virtualenv • sudo easy_install virtualenv, then add this to your .bashrc • Create a new Python environment • virtualenv myproject --no-site-packages Don’t inherit from global site-packages directory • virtualenv myproject --no-site-packages --distribute Uses distribute instead of setup_tools • I think it’s best to ensure your new env does not inherit packages from your global site-packages directory • This is ok but to make things easier to manage, let’s use virtualenvwrapper (Thanks Doug Hellmann)
  • 7. virtualenvwrapper • Organises your virtualenvs into one spot # Put this in your .bash_profile or .bashrc export WORKON_HOME=$HOME/.virtualenvs source /usr/local/bin/virtualenvwrapper_bashrc • Separates your virtualenvs from your project source • Nice environment event hooks for automation of repetitive tasks (cd project on post_activate) • Basically, it makes your use of virtualenv more efficient • Now we need the perfect package management tool for installing packages in our env...
  • 8. VirtualEnvWrapper scripts • mkvirtualenv (create a new virtualenv) • rmvirtualenv (remove an existing virtualenv) • workon (change the current virtualenv) • add2virtualenv (add external packages in a .pth file to current virtualenv) • cdsitepackages (cd into the site-packages directory of current virtualenv) • cdvirtualenv (cd into the root of the current virtualenv) • deactivate (deactivate virtualenv, which calls several hooks)
  • 9. Virtual EnvWrapper Hooks • postmkvirtualenv • prermvirtualenv • postrmvirtualenv • postactivate • predeactivate • postdeactivate
  • 10. Introducing pip • Pip - Pip Installs Packages, nothing more, nothing less • It’s good, James Bennet explains - http://goo.gl/F9m2N • Great at re-producing builds of specific versions of packages, just remember to use versioning for each package. • Every project needs at least one requirements file
  • 11. Installing packages • By default, searches PyPi just like easy_install • Can also install from: - tarballs containing a setup.py script - Editable checkouts from VCS repos - Editable checkouts from VCS repos with revision info • Can install packages from Pip bundles
  • 12. Installing packages • Installation - sudo easy_install pip • Workflow 1. Make or activate virtual env 2. Install (and search for) packages • pip search pip install package-name (latest) pip install package-name==1.4.5 (specific) pip install package-name>=1.4.5 (at least...) • Install packages from requirements file pip install -r requirements.txt • Freeze current packages to produce requirements file
  • 13. Terminal action! • Finally, let’s write some code • For those watching at home, go checkout Mathemtism’s excellent screen cast at http://goo.gl/wWkti
  • 14. What about my editor? • Good Python editors and IDE’s should support virtual env • PyCharm does by you telling it which python interpreter should be used for each project, it then nows which site packages directory to use.
  • 15. Summary • Isolated Python environments are a must • VirtualEnv,VirtualEnvWrapper are THE way to manage them
  • 16. Docs • VirtualEnv http://www.virtualenv.org/en/latest/ • VirtualEnvWrapper http://www.doughellmann.com/docs/virtualenvwrapper/ • Pip http://www.pip-installer.org/en/latest/
  • 17. References • Pip and VirtualEnv (Awesome!) http://mathematism.com/2009/07/30/presentation-pip- and-virtualenv/ • Tools of the Modern Python Hacker:Virtualenv, Fabric and Pip http://www.clemesha.org/blog/modern-python-hacker- tools-virtualenv-fabric-pip • Notes on using pip and virtualenv with Django http://www.saltycrane.com/blog/2009/05/notes-using-pip- and-virtualenv-django/
  • 18. Thanks! • Ryan Blunden ryan.blunden@gmail.com @ryan_blunden

Hinweis der Redaktion

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n