Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installed packages with pip are not shown in pip freeze?

I'm using virtualenv and pip on Debian Wheezy. I'm having an odd problem where packages appear to install OK, but then aren't visible in the virtualenv.

This is my requirements.txt file:

Django==1.7.7
psycopg2==2.5.4
django-geojson==2.6.0

If I install it with pip from inside my virtualenv, it says everything has been installed:

(.venv)$ sudo pip install -r requirements.txt
Requirement already satisfied (use --upgrade to upgrade): Django==1.7.7 in /usr/local/lib/python2.7/dist-packages (from -r requirements/base.txt (line 1))
Requirement already satisfied (use --upgrade to upgrade): psycopg2==2.5.4 in /usr/local/lib/python2.7/dist-packages (from -r requirements/base.txt (line 2))
Requirement already satisfied (use --upgrade to upgrade): django-geojson==2.6.0 in /usr/local/lib/python2.7/dist-packages (from -r requirements/base.txt (line 3))
Requirement already satisfied (use --upgrade to upgrade): six in /usr/local/lib/python2.7/dist-packages (from django-geojson==2.6.0->-r requirements/base.txt (line 3))
Cleaning up...

But then if I do pip freeze to check what is installed, it looks like pip thinks I have a completely different set of packages, and in particular it doesn't see djgeojson there:

(.venv)$ pip freeze
Django==1.7.4
argparse==1.2.1
coverage==3.7.1
distribute==0.6.24
django-debug-toolbar==1.2.1
gunicorn==19.3.0
psycopg2==2.5.4
requirements==0.1
setproctitle==1.1.8
sqlparse==0.1.14
wsgiref==0.1.2

And if I fire up a Python terminal, Python can't see djgeojson.

Why is this happening? It is quite confusing.

like image 943
Richard Avatar asked Apr 01 '15 10:04

Richard


People also ask

Does pip freeze show dependencies?

pip freeze might seem very useful initially but it can mess up your project because of the following reasons: It dumps all the libraries installed in your project including dependencies and sub-dependencies in the requirements. txt file. It still misses out on the libraries that are not installed using pip.

How do I freeze pip requirements?

The most common command is pip freeze > requirements. txt , which records an environment's current package list into requirements. txt. If you want to install the dependencies in a virtual environment, create and activate that environment first, then use the Install from requirements.


Video Answer


1 Answers

Your problem is that you've installed requirements with sudo and they were installed in your system python library folder instead and not in your virtual environment's venv library.

What to do? Run the same command but this time without sudo: pip install -r requirements.txt. This will run pip from the virtual environment and install packages to the right place.

When you activate a virtual environment e.q with source path/to/my/venv/bin/acivate the path variable $PATH of your current user is updated and then when you run something with sudo, this new $PATH that you've just updated when activating the virtual environment is no longer the same. Same thing happens when you open a new shell window or logs in as a different user with su or running sudo, $PATH variable is not a global system one.

like image 189
Tim Rijavec Avatar answered Sep 21 '22 01:09

Tim Rijavec