SlideShare ist ein Scribd-Unternehmen logo
1 von 29
Downloaden Sie, um offline zu lesen
pip + virtualenv
More WHY?
than HOW?
What’s pip?
pip is a tool for installing and
managing Python packages.
It’s similar to yum,
apt, homebrew,
rubygems, etc...
How do you get pip?
$ easy_install pip
Wait. What’s easy_install?

easy_install is a tool for
installing and managing
Python packages.
But wait; there’s more!
If you’re using a *NIX system, you can
probably install pip via your OS’s package
manager.
You can probably also install Python packages
using your OS’s package manager.
So why use pip over X?
easy_install:
● I honestly don’t know, but if you enjoy parroting, click here: http:
//www.pip-installer.org/en/latest/other-tools.html#pip-comparedto-easy-install
Your OS’s package manager:
● Versions are usually outdated, especially for large projects
Basic pip usage...
# Searching...
$ pip search json
# Installing...
$ sudo pip install simplejson
# Updating

$ sudo pip install --upgrade simplejson
# Uninstalling

$ sudo pip uninstall simplejson
What’s virtualenv?

virtualenv is a tool for
creating isolated Python
environments.
It’s similar to chroot,
FreeBSD jails, Ruby’s
bundler, etc...
Why or when do
we need
virtualenv?
To answer that, we
have to ask another
question.
What happens when
you install
something with pip?
A system-wide install!
Why is this bad?
● Only one version for the entire
machine.
● You’ll end up with a lot of packages on
/usr/local
● I totally made the second one up so I
can use bullet points
Main use cases:
● Different projects are going to need
different versions of packages.
● Provide packages only to the projects
that need them.
One virtualenv for
each project/repo
you’re working on.
TIP!
Basic virtualenv usage...
# Creating a virtualenv...
$ virtualenv ENV # creates a directory named ENV
# Activating a virtualenv
$ source bin/activate
# Manage your virtualenv’s packages
# A new virtualenv includes pip in ENV/bin/pip
...
# Leaving a virtualenv
$ source bin/deactivate
CONFESSION TIME

I don’t really use virtualenv.
Use virtualenvwrapper.
Vanilla virtualenv makes
me want to cry.
Basic virtualenvwrapper
usage...
# Creating a virtualenv...
$ mkvirtualenv env_name
# Activating a virtualenv
$ workon env_name
# Manage your virtualenv’s packages
# (install, update, uninstall, etc)
...
# Leaving a virtualenv
$ deactivate
Everything that happens
between workon and
deactivate only apply to
the current virtualenv.
REMEMBER!
For virtualenvs that you
can “pass around”
# Save all the packages you are using to a file...
$ pip freeze > requirements.txt
# Install all packages you needed from a file...
$ pip install -r requirements.txt
# Especially useful for projects with more than one person
working on it...
BONUS
Because non sequitur...
virtualenvs and
environment variables...
#!/bin/bash
# $WORKON_HOME/pizzapy/bin/postactivate
export DB_NAME=pizzapy
export DB_USER=root
export DB_PASSWORD=a1f9234a0f2cbd028
export DB_HOST=192.20.12.98
export DB_PORT=3306
virtualenvs and
environment variables...
# in your Python code...
import os
DATABASES = {
‘default’: {
‘NAME’: os.environ[‘DB_NAME’]
‘USER’: os.environ[‘DB_USER’]
‘PASSWORD’: os.environ[‘DB_NAME’]
‘NAME’: os.environ[‘DB_PASSWORD’]
‘HOST’: os.environ[‘DB_HOST’]
}
}
END
Questions?

Weitere Àhnliche Inhalte

Was ist angesagt?

Vagrant
VagrantVagrant
Vagrant
Evans Ye
 
Node.js, Vagrant, Chef, and Mathoid @ Benetech
Node.js, Vagrant, Chef, and Mathoid @ BenetechNode.js, Vagrant, Chef, and Mathoid @ Benetech
Node.js, Vagrant, Chef, and Mathoid @ Benetech
Christopher Bumgardner
 
Oscar: Rapid Iteration with Vagrant and Puppet Enterprise - PuppetConf 2013
Oscar: Rapid Iteration with Vagrant and Puppet Enterprise - PuppetConf 2013Oscar: Rapid Iteration with Vagrant and Puppet Enterprise - PuppetConf 2013
Oscar: Rapid Iteration with Vagrant and Puppet Enterprise - PuppetConf 2013
Puppet
 

Was ist angesagt? (20)

Packaging in Python? Don't Roll the Dice.
Packaging in Python? Don't Roll the Dice.Packaging in Python? Don't Roll the Dice.
Packaging in Python? Don't Roll the Dice.
 
TYPO3 CMS deployment with Jenkins CI
TYPO3 CMS deployment with Jenkins CITYPO3 CMS deployment with Jenkins CI
TYPO3 CMS deployment with Jenkins CI
 
Python environments
Python environmentsPython environments
Python environments
 
Vagrant for Virtualized Development
Vagrant for Virtualized DevelopmentVagrant for Virtualized Development
Vagrant for Virtualized Development
 
Vagrant
Vagrant Vagrant
Vagrant
 
Buildout: creating and deploying repeatable applications in python
Buildout: creating and deploying repeatable applications in pythonBuildout: creating and deploying repeatable applications in python
Buildout: creating and deploying repeatable applications in python
 
Vagrant
VagrantVagrant
Vagrant
 
Vagrant presentation
Vagrant presentationVagrant presentation
Vagrant presentation
 
DevOps Series: Extending vagrant with Puppet for configuration management
DevOps Series: Extending vagrant with Puppet for configuration managementDevOps Series: Extending vagrant with Puppet for configuration management
DevOps Series: Extending vagrant with Puppet for configuration management
 
Vagrant-Overview
Vagrant-OverviewVagrant-Overview
Vagrant-Overview
 
Python - Flask - miniapp - ignite
Python - Flask - miniapp - ignitePython - Flask - miniapp - ignite
Python - Flask - miniapp - ignite
 
Node.js, Vagrant, Chef, and Mathoid @ Benetech
Node.js, Vagrant, Chef, and Mathoid @ BenetechNode.js, Vagrant, Chef, and Mathoid @ Benetech
Node.js, Vagrant, Chef, and Mathoid @ Benetech
 
Webinar - Auto-deploy Puppet Enterprise: Vagrant and Oscar
Webinar - Auto-deploy Puppet Enterprise: Vagrant and OscarWebinar - Auto-deploy Puppet Enterprise: Vagrant and Oscar
Webinar - Auto-deploy Puppet Enterprise: Vagrant and Oscar
 
Vagrant: The Oscar Plug-in
Vagrant: The Oscar Plug-inVagrant: The Oscar Plug-in
Vagrant: The Oscar Plug-in
 
Django Dev Environment Howto
Django Dev Environment HowtoDjango Dev Environment Howto
Django Dev Environment Howto
 
Virtualization for Developers
Virtualization for DevelopersVirtualization for Developers
Virtualization for Developers
 
Virtualization for Developers
Virtualization for DevelopersVirtualization for Developers
Virtualization for Developers
 
How to manage Microsoft Azure with open source
How to manage Microsoft Azure with open sourceHow to manage Microsoft Azure with open source
How to manage Microsoft Azure with open source
 
Puppet without Root - PuppetConf 2013
Puppet without Root - PuppetConf 2013Puppet without Root - PuppetConf 2013
Puppet without Root - PuppetConf 2013
 
Oscar: Rapid Iteration with Vagrant and Puppet Enterprise - PuppetConf 2013
Oscar: Rapid Iteration with Vagrant and Puppet Enterprise - PuppetConf 2013Oscar: Rapid Iteration with Vagrant and Puppet Enterprise - PuppetConf 2013
Oscar: Rapid Iteration with Vagrant and Puppet Enterprise - PuppetConf 2013
 

Andere mochten auch

Django e il Rap Elia Contini
Django e il Rap Elia ContiniDjango e il Rap Elia Contini
Django e il Rap Elia Contini
WEBdeBS
 

Andere mochten auch (20)

We Buy Cheese in a Cheese Shop
We Buy Cheese in a Cheese ShopWe Buy Cheese in a Cheese Shop
We Buy Cheese in a Cheese Shop
 
Python, Development Environment for Windows
Python, Development Environment for WindowsPython, Development Environment for Windows
Python, Development Environment for Windows
 
Python Recipes for django girls seoul
Python Recipes for django girls seoulPython Recipes for django girls seoul
Python Recipes for django girls seoul
 
Website optimization
Website optimizationWebsite optimization
Website optimization
 
á„…á…Ąá„‹á…”á„á…łá„‚á…”á†Œ á„á…©á„á…ł 2015 á„‘á…Ąá„‹á…”á„á…©á†«
á„…á…Ąá„‹á…”á„á…łá„‚á…”á†Œ á„á…©á„á…ł 2015 á„‘á…Ąá„‹á…”á„á…©á†«á„…á…Ąá„‹á…”á„á…łá„‚á…”á†Œ á„á…©á„á…ł 2015 á„‘á…Ąá„‹á…”á„á…©á†«
á„…á…Ąá„‹á…”á„á…łá„‚á…”á†Œ á„á…©á„á…ł 2015 á„‘á…Ąá„‹á…”á„á…©á†«
 
PythonBrasil[8] closing
PythonBrasil[8] closingPythonBrasil[8] closing
PythonBrasil[8] closing
 
Load testing
Load testingLoad testing
Load testing
 
Overview of Testing Talks at Pycon
Overview of Testing Talks at PyconOverview of Testing Talks at Pycon
Overview of Testing Talks at Pycon
 
Vim for Mere Mortals
Vim for Mere MortalsVim for Mere Mortals
Vim for Mere Mortals
 
NoSql Day - Apertura
NoSql Day - AperturaNoSql Day - Apertura
NoSql Day - Apertura
 
PyClab.__init__(self)
PyClab.__init__(self)PyClab.__init__(self)
PyClab.__init__(self)
 
2007 - ćș”ç”šçł»ç»Ÿè„†ćŒ±æ€§æŠ‚èźș
2007 - ćș”ç”šçł»ç»Ÿè„†ćŒ±æ€§æŠ‚èźș 2007 - ćș”ç”šçł»ç»Ÿè„†ćŒ±æ€§æŠ‚èźș
2007 - ćș”ç”šçł»ç»Ÿè„†ćŒ±æ€§æŠ‚èźș
 
2 × 3 = 6
2 × 3 = 62 × 3 = 6
2 × 3 = 6
 
Django e il Rap Elia Contini
Django e il Rap Elia ContiniDjango e il Rap Elia Contini
Django e il Rap Elia Contini
 
Django - The Web framework for perfectionists with deadlines
Django - The Web framework for perfectionists with deadlinesDjango - The Web framework for perfectionists with deadlines
Django - The Web framework for perfectionists with deadlines
 
NoSql Day - Chiusura
NoSql Day - ChiusuraNoSql Day - Chiusura
NoSql Day - Chiusura
 
EuroDjangoCon 2009 - Ein RĂŒckblick
EuroDjangoCon 2009 - Ein RĂŒckblickEuroDjangoCon 2009 - Ein RĂŒckblick
EuroDjangoCon 2009 - Ein RĂŒckblick
 
Super Advanced Python –act1
Super Advanced Python –act1Super Advanced Python –act1
Super Advanced Python –act1
 
User-centered open source
User-centered open sourceUser-centered open source
User-centered open source
 
Authentication & Authorization in ASPdotNet MVC
Authentication & Authorization in ASPdotNet MVCAuthentication & Authorization in ASPdotNet MVC
Authentication & Authorization in ASPdotNet MVC
 

Ähnlich wie Pip + virtualenv

Using the pip package manager for Odoo
Using the pip package manager for OdooUsing the pip package manager for Odoo
Using the pip package manager for Odoo
Odoo
 
Django & Buildout (en)
Django & Buildout (en)Django & Buildout (en)
Django & Buildout (en)
zerok
 
Development with Ansible & VMs
Development with Ansible & VMsDevelopment with Ansible & VMs
Development with Ansible & VMs
Jeff Schenck
 

Ähnlich wie Pip + virtualenv (20)

Python virtualenv & pip in 90 minutes
Python virtualenv & pip in 90 minutesPython virtualenv & pip in 90 minutes
Python virtualenv & pip in 90 minutes
 
Arbeiten mit distribute, pip und virtualenv
Arbeiten mit distribute, pip und virtualenvArbeiten mit distribute, pip und virtualenv
Arbeiten mit distribute, pip und virtualenv
 
Python Versions and Dependencies Made Easy
Python Versions and Dependencies Made EasyPython Versions and Dependencies Made Easy
Python Versions and Dependencies Made Easy
 
Using the pip package manager for Odoo
Using the pip package manager for OdooUsing the pip package manager for Odoo
Using the pip package manager for Odoo
 
Using the "pip" package manager for Odoo/OpenERP - Opendays 2014
Using the "pip" package manager for Odoo/OpenERP - Opendays 2014Using the "pip" package manager for Odoo/OpenERP - Opendays 2014
Using the "pip" package manager for Odoo/OpenERP - Opendays 2014
 
AWS EC2 Ubuntu Instance - Step-by-Step Deployment Guide
AWS EC2 Ubuntu Instance - Step-by-Step Deployment GuideAWS EC2 Ubuntu Instance - Step-by-Step Deployment Guide
AWS EC2 Ubuntu Instance - Step-by-Step Deployment Guide
 
Django & Buildout (en)
Django & Buildout (en)Django & Buildout (en)
Django & Buildout (en)
 
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
 
A quick overview of why to use and how to set up iPython notebooks for research
A quick overview of why to use and how to set up iPython notebooks for researchA quick overview of why to use and how to set up iPython notebooks for research
A quick overview of why to use and how to set up iPython notebooks for research
 
Arbeiten mit distribute, pip und virtualenv
Arbeiten mit distribute, pip und virtualenvArbeiten mit distribute, pip und virtualenv
Arbeiten mit distribute, pip und virtualenv
 
Pwnstaller
PwnstallerPwnstaller
Pwnstaller
 
Cooking Perl with Chef: Real World Tutorial with Jitterbug
Cooking Perl with Chef: Real World Tutorial with JitterbugCooking Perl with Chef: Real World Tutorial with Jitterbug
Cooking Perl with Chef: Real World Tutorial with Jitterbug
 
Automate Yo' Self
Automate Yo' SelfAutomate Yo' Self
Automate Yo' Self
 
Organize your chickens: NuGet for the enterprise
Organize your chickens: NuGet for the enterpriseOrganize your chickens: NuGet for the enterprise
Organize your chickens: NuGet for the enterprise
 
Installing OpenCV 4 on Ubuntu 18.x
Installing OpenCV 4 on Ubuntu 18.xInstalling OpenCV 4 on Ubuntu 18.x
Installing OpenCV 4 on Ubuntu 18.x
 
Vagrant and puppet: Deployment made easy
Vagrant and puppet: Deployment made easyVagrant and puppet: Deployment made easy
Vagrant and puppet: Deployment made easy
 
Development with Ansible & VMs
Development with Ansible & VMsDevelopment with Ansible & VMs
Development with Ansible & VMs
 
Python+gradle
Python+gradlePython+gradle
Python+gradle
 
Ci For The Web 2.0 Guy Or Gal
Ci For The Web 2.0 Guy Or GalCi For The Web 2.0 Guy Or Gal
Ci For The Web 2.0 Guy Or Gal
 
Python packaging and dependency resolution
Python packaging and dependency resolutionPython packaging and dependency resolution
Python packaging and dependency resolution
 

KĂŒrzlich hochgeladen

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

KĂŒrzlich hochgeladen (20)

Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 

Pip + virtualenv

  • 3. What’s pip? pip is a tool for installing and managing Python packages.
  • 4. It’s similar to yum, apt, homebrew, rubygems, etc...
  • 5. How do you get pip? $ easy_install pip
  • 6. Wait. What’s easy_install? easy_install is a tool for installing and managing Python packages.
  • 7.
  • 8. But wait; there’s more! If you’re using a *NIX system, you can probably install pip via your OS’s package manager. You can probably also install Python packages using your OS’s package manager.
  • 9.
  • 10. So why use pip over X? easy_install: ● I honestly don’t know, but if you enjoy parroting, click here: http: //www.pip-installer.org/en/latest/other-tools.html#pip-comparedto-easy-install Your OS’s package manager: ● Versions are usually outdated, especially for large projects
  • 11. Basic pip usage... # Searching... $ pip search json # Installing... $ sudo pip install simplejson # Updating
 $ sudo pip install --upgrade simplejson # Uninstalling
 $ sudo pip uninstall simplejson
  • 12. What’s virtualenv? virtualenv is a tool for creating isolated Python environments.
  • 13. It’s similar to chroot, FreeBSD jails, Ruby’s bundler, etc...
  • 14. Why or when do we need virtualenv?
  • 15. To answer that, we have to ask another question.
  • 16. What happens when you install something with pip? A system-wide install!
  • 17. Why is this bad? ● Only one version for the entire machine. ● You’ll end up with a lot of packages on /usr/local ● I totally made the second one up so I can use bullet points
  • 18. Main use cases: ● Different projects are going to need different versions of packages. ● Provide packages only to the projects that need them.
  • 19. One virtualenv for each project/repo you’re working on. TIP!
  • 20. Basic virtualenv usage... # Creating a virtualenv... $ virtualenv ENV # creates a directory named ENV # Activating a virtualenv $ source bin/activate # Manage your virtualenv’s packages # A new virtualenv includes pip in ENV/bin/pip ... # Leaving a virtualenv $ source bin/deactivate
  • 21. CONFESSION TIME I don’t really use virtualenv.
  • 23. Basic virtualenvwrapper usage... # Creating a virtualenv... $ mkvirtualenv env_name # Activating a virtualenv $ workon env_name # Manage your virtualenv’s packages # (install, update, uninstall, etc) ... # Leaving a virtualenv $ deactivate
  • 24. Everything that happens between workon and deactivate only apply to the current virtualenv. REMEMBER!
  • 25. For virtualenvs that you can “pass around” # Save all the packages you are using to a file... $ pip freeze > requirements.txt # Install all packages you needed from a file... $ pip install -r requirements.txt # Especially useful for projects with more than one person working on it...
  • 27. virtualenvs and environment variables... #!/bin/bash # $WORKON_HOME/pizzapy/bin/postactivate export DB_NAME=pizzapy export DB_USER=root export DB_PASSWORD=a1f9234a0f2cbd028 export DB_HOST=192.20.12.98 export DB_PORT=3306
  • 28. virtualenvs and environment variables... # in your Python code... import os DATABASES = { ‘default’: { ‘NAME’: os.environ[‘DB_NAME’] ‘USER’: os.environ[‘DB_USER’] ‘PASSWORD’: os.environ[‘DB_NAME’] ‘NAME’: os.environ[‘DB_PASSWORD’] ‘HOST’: os.environ[‘DB_HOST’] } }