Installing packages in a virtual environment

suggest change

Once your virtual environment has been activated, any package that you install will now be installed in the virtualenv & not globally. Hence, new packages can be without needing root privileges.

To verify that the packages are being installed into the virtualenv run the following command to check the path of the executable that is being used :

(<Virtualenv Name) $ which python
/<Virtualenv Directory>/bin/python

(Virtualenv Name) $ which pip
/<Virtualenv Directory>/bin/pip

Any package then installed using pip will be installed in the virtualenv itself in the following directory :

/<Virtualenv Directory>/lib/python2.7/site-packages/

Alternatively, you may create a file listing the needed packages.

requirements.txt:

requests==2.10.0

Executing:

# Install packages from requirements.txt
pip install -r requirements.txt

will install version 2.10.0 of the package requests.

You can also get a list of the packages and their versions currently installed in the active virtual environment:

# Get a list of installed packages
pip freeze

# Output list of packages and versions into a requirement.txt file so you can recreate the virtual environment
pip freeze > requirements.txt

Alternatively, you do not have to activate your virtual environment each time you have to install a package. You can directly use the pip executable in the virtual environment directory to install packages.

$ /<Virtualenv Directory>/bin/pip install requests

More information about using pip can be found on the PIP topic.

Since you’re installing without root in a virtual environment, this is not a global install, across the entire system - the installed package will only be available in the current virtual environment.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Virtual environments:
* Installing packages in a virtual environment

Table Of Contents
2 Filter
3 List
7 Loops
22 Reduce
27 Classes
31 Set
40 Virtual environments
42 Tuple
45 Enum
62 Sockets
89 urllib
92 Idioms
104 Stack
105 Profiling
109 Logging
111 os module
118 Mixins
120 ArcPy
126 Arrays
132 2to3 tool
135 Unicode
138 Neo4j
140 Curses
141 Templates
145 heapq
146 tkinter
154 Audio
155 pyglet
157 ijson
160 Flask
161 Groupby
163 pygame
165 hashlib
166 Gzip
167 ctypes
185 pyaudio
186 shelve