Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pip requirements outputting global packages

I have a Virtual env for my django project, but when I hit pip freeze, I get what must be a global site package list, includes too many packages, like ubuntu packages and so much irrelevant stuff. This happens whether virtualenv is active or not. My site packages list looks a bit slim too, so I wonder whether venv has been working at all.

(env)~/code/django/ssc/dev/env/lib/python2.7/site-packages> ls
django
Django-1.4-py2.7.egg-info
easy-install.pth
pip-1.0.2-py2.7.egg
setuptools-0.6c11-py2.7.egg
setuptools.pth

What's my problem?

like image 955
KindOfGuy Avatar asked Sep 23 '12 13:09

KindOfGuy


People also ask

How do I install all libraries in requirements txt?

Use the pip install -r requirements. txt command to install all of the Python modules and packages listed in your requirements. txt file.

Does pip use requirements txt?

Requirements files serve as a list of items to be installed by pip, when using pip install. Files that use this format are often called “pip requirements. txt files”, since requirements. txt is usually what these files are named (although, that is not a requirement).


2 Answers

If your virtual environment has access to the system's site-packages dir (ie. you used virtualenv --system-site-packages) then it's normal for the list to be a rather long one.

Compare the following:

$ virtualenv --system-site-packages v1 && source v1/bin/activate
$ (v1) pip freeze | wc -l  # 100

$ virtualenv v2 && source v2/bin/activate
$ (v2) pip freeze | wc -l  # 2

Can you try recreating the virtualenv?

Alternatively, adding a no-global-site-packages.txt file should tell pip to ignore the global site-packages:

$ touch $VIRTUAL_ENV/lib/python${version}/no-global-site-packages.txt
like image 184
gvalkov Avatar answered Sep 28 '22 07:09

gvalkov


I don't understand why the most concise option was just left in the comments. Since I have just almost missed it I will put it here as a separate answer with some tweaks. You can add --local flag with your pip freeze if you are running a virtual env with system-site-packages enables. So, if you had:

py -m venv --system-site-packages env

To make sure you are not getting all system deps into your requirements.txt, just run:

python -m pip freeze --local > requirements.txt

Another, a bit more elaborate option, but still viable because dependencies are not supposed to change all that often, would be to go into pyvenv.cfg file located in your virtual env library and manually change:

include-system-site-packages = true/false
like image 45
yuranos Avatar answered Sep 28 '22 06:09

yuranos