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?
Use the pip install -r requirements. txt command to install all of the Python modules and packages listed in your requirements. txt file.
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).
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With