

Successfully installed stevedore-1.18.0 virtualenv-15.1.0 virtualenv-clone-0.2.6 virtualenvwrapper-4.7.2 The extensions include wrappers for creating and deleting virtual environments and otherwise managing our development workflow, making it easier to work on more than one project at a time without introducing conflicts in their dependencies. Virtualenvwrapper is a set of extensions to virtualenv tool. If we switch to work on a different project (with its own environment), we can run deactivate to stop using one environment, and then source env/bin/activate to activate the other.

The adjustments to our shell only last for as long as the terminal is open, so we'll need to remember to rerun source env/bin/activate each time you close and open our terminal window. So, now we can just run pip install requests (instead of env/bin/pip install requests) and pip will install the library into the environment, instead of globally. This script, which can be executed with source env/bin/activate, simply adjusts a few variables in our shell (temporarily) so that when we type python, we actually get the Python binary inside the virtualenv instead of the global one: Instead of typing env/bin/python and env/bin/pip every time, we can run a script to activate the environment. Type "help", "copyright", "credits" or "license" for more information. Now, instead of typing python to get a Python shell, we type env/bin/python: Notice that we didn't need to use sudo this time, because we're not installing requests globally, we're just installing it inside our home directory. home/k/myproject/env/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90:ĭownloading requests-2.7.0-py2.p圓-none-any.whl (470kB) Let's start by using the copy of pip to install requests into the virtualenv (rather than globally): This is where the local copy of the python binary and the pip installer exists. If we look inside the env directory we just created, we'll see a few subdirectories: It's a common convention to call this directory env, and to put it inside our project directory (so, say we keep our code at ~/myproject/, the environment will be at ~/myproject/env/ - each project gets its own env). Here, env is just the name of the directory we want to create our virtual environment inside. Start by changing directory into the root of our project directory, and then use the virtualenv command-line tool to create a new environment: We only need the virtualenv tool itself when we want to create a new environment. We can then use it in our program just as before.

When we install a package from PyPI using the copy of pip that's created by the virtualenv tool, it will install the package into the site-packages directory inside the virtualenv directory.
