How to isolatepython installationswith virtualenvDivick Kishore,iWish Inc, www.iwishapp.com,divick@iwishapp.com
When to use virtualenv?● If you dont have sudo or root access on a  development machine● You want to try out a new package...
What is Virtualenv● Tool to create isolated python environment  quite like chroot jail on Unix systems● Difference being t...
Virtualenv setup and usage● Install Virtualenv  $ pip install virtualenv● Create a Virtualenv  $ virtualenv --no-site-pack...
Enter the Virtualenv● On entering the virtualenv, notice the  command prompt change. It has a (ve) prefix  now     $ sourc...
Install packages in newly createdVirtualenv● On entering the virtualenv, see the list of  packages installed     (ve) $ pi...
Exit VirtualEnv● Simply run  (ve) $ deactivate  $● See the command prompt change back to $  without ve prefix
Summary● Virtualenv and pip are must use tools for any  python developer● It seem daunting at first, but both Virtualenv  ...
Upcoming SlideShare
Loading in …5
×

How to isolate python installations with virtualenv

1,044 views
864 views

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,044
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
5
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

How to isolate python installations with virtualenv

  1. 1. How to isolatepython installationswith virtualenvDivick Kishore,iWish Inc, www.iwishapp.com,divick@iwishapp.com
  2. 2. When to use virtualenv?● If you dont have sudo or root access on a development machine● You want to try out a new package without polluting the system directories / global python installation● You want to test your code with a new version of a library without uninstalling the previous version● You want to test your code in an isolated environment before you deploy it to a production server
  3. 3. What is Virtualenv● Tool to create isolated python environment quite like chroot jail on Unix systems● Difference being that program running in chroot jail cannot access anything outside of chrooted folder while virtualenv allows installation of multiple versions of a single library
  4. 4. Virtualenv setup and usage● Install Virtualenv $ pip install virtualenv● Create a Virtualenv $ virtualenv --no-site-packages ve ○ The name of virtualenv can be anything you like ○ --no-site-packages is optional as it is the default ○ The way it works is by creating symlinks to your global python installation● Use the isolated Python environment ○ To enter the environment run: $ source ./ve/bin/activate (ve) $
  5. 5. Enter the Virtualenv● On entering the virtualenv, notice the command prompt change. It has a (ve) prefix now $ source ./ve/bin/activate (ve) $● Before entering the virtualenv, see the list of packages installed $ pip freeze Brlapi==0.5.5 CouchDB==0.8 Django==1.3 Fabric==1.3.4 ...
  6. 6. Install packages in newly createdVirtualenv● On entering the virtualenv, see the list of packages installed (ve) $ pip freeze (ve) $ ○ As you can see above, there are no packages installed and you have a clean environment to begin testing● Now you can install any package that you like which will get installed in the virtualenv ve that you just created (ve) $ pip install <package-name> (ve) $ pip install -r requirements.txt
  7. 7. Exit VirtualEnv● Simply run (ve) $ deactivate $● See the command prompt change back to $ without ve prefix
  8. 8. Summary● Virtualenv and pip are must use tools for any python developer● It seem daunting at first, but both Virtualenv and Pip are quite easy to setup and use● Use Pip and Virtualenv in combination earlyon to avoid headaches in long run

×