python:virtual_environments
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
python:virtual_environments [2014/11/25 11:33] – created kauffman | python:virtual_environments [2016/06/30 11:56] (current) – [Other things you should know] kauffman | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Python Virtual Environments ====== | ====== Python Virtual Environments ====== | ||
+ | |||
+ | ==== What and Why ==== | ||
+ | A Virtual Environment is a tool to keep the dependencies required by different projects in separate places, by creating virtual Python environments for them. It solves the “Project X depends on version 1.x but, Project Y needs 4.x” dilemma, and keeps your global site-packages directory clean and manageable. For example, you can work on a project which requires Django 1.3 while also maintaining a project which requires Django 1.0. ((http:// | ||
+ | |||
+ | ==== Other things you should know ==== | ||
+ | - https:// | ||
+ | - http:// | ||
+ | ==== Using Virtual Environments ==== | ||
+ | The python virtual environment package is installed by default on most CS machines. To make sure you can do the following: | ||
+ | < | ||
+ | user@computer: | ||
+ | / | ||
+ | </ | ||
+ | |||
+ | ==== Creating a new project ==== | ||
+ | < | ||
+ | user@hester: | ||
+ | The --no-site-packages flag is deprecated; it is now the default behavior. | ||
+ | New python executable in exampleproject/ | ||
+ | Installing | ||
+ | distribute................................................................................done. | ||
+ | Installing pip...............done. | ||
+ | </ | ||
+ | < | ||
+ | user@computer: | ||
+ | total 4 | ||
+ | drwxrwxr-x 2 user group 4096 Nov 25 10:16 bin | ||
+ | drwxrwxr-x 2 user group 30 Nov 25 10:16 include | ||
+ | drwxrwxr-x 3 user group 30 Nov 25 10:16 lib | ||
+ | drwxrwxr-x 2 user group 56 Nov 25 10:16 local | ||
+ | </ | ||
+ | < | ||
+ | user@computer: | ||
+ | </ | ||
+ | |||
+ | ==== Activate ==== | ||
+ | Now you need to activate your virtual environment. This will setup some path variables to make the environments bin and lib directory to be the default. | ||
+ | < | ||
+ | user@computer: | ||
+ | (exampleproject)user@computer: | ||
+ | </ | ||
+ | |||
+ | ==== Installing Modules ==== | ||
+ | After activating the virtual environment you will notice that your prompt changed a little. This is not the only thing that has changed. Your $PATH and default python have changed as well (just checkout the bin/ | ||
+ | |||
+ | Notice that the ' | ||
+ | < | ||
+ | (exampleproject)user@computer: | ||
+ | / | ||
+ | </ | ||
+ | < | ||
+ | (exampleproject)user@computer: | ||
+ | / | ||
+ | </ | ||
+ | < | ||
+ | (exampleproject)user@computer: | ||
+ | / | ||
+ | </ | ||
+ | |||
+ | So to actually install your own python modules you can use ' | ||
+ | < | ||
+ | (exampleproject)user@computer: | ||
+ | Downloading/ | ||
+ | Downloading docopt-0.6.2.tar.gz | ||
+ | Running setup.py egg_info for package docopt | ||
+ | |||
+ | Installing collected packages: docopt | ||
+ | Running setup.py install for docopt | ||
+ | |||
+ | Successfully installed docopt | ||
+ | Cleaning up... | ||
+ | </ | ||
+ | |||
+ | Notice where docopt was installed (~/ | ||
+ | < | ||
+ | (exampleproject)user@computer: | ||
+ | -rw------- 1 user group 19946 Mar 8 23:12 local/ | ||
+ | -rw------- 1 user group 26140 Mar 8 23:12 local/ | ||
+ | |||
+ | local/ | ||
+ | total 40 | ||
+ | -rw------- 1 user group 1 Mar 8 23:12 dependency_links.txt | ||
+ | -rw------- 1 user group 86 Mar 8 23:12 installed-files.txt | ||
+ | -rw------- 1 user group 21525 Mar 8 23:12 PKG-INFO | ||
+ | -rw------- 1 user group 651 Mar 8 23:12 SOURCES.txt | ||
+ | -rw------- 1 user group 7 Mar 8 23:12 top_level.txt | ||
+ | </ | ||
+ | |||
+ | |||
+ | ==== Deactivate ==== | ||
+ | To deactivate or stop working on your environment use the function that gets sourced when you activate your environment: | ||
+ | < | ||
+ | (exampleproject)user@computer: | ||
+ | user@computer: | ||
+ | </ |
/var/lib/dokuwiki/data/pages/python/virtual_environments.txt · Last modified: 2016/06/30 11:56 by kauffman