简体   繁体   中英

pip freeze > requirements.txt including all system installed packages inside virtualenv

Bit of backstory, I'm relatively new to Python and development in general and have stupidly been installing project specific packages as system packages. This is now causing me issues when trying to create requirements.txt files for specific projects, inside of virtualenvs.

For example, I've installed Kivy system wide and every time I create a new env with a requirements file I'm getting the below (yes the env is active):

$ pip freeze > requirements.txt
$ cat requirements.txt
Kivy==1.9.1
Pillow==2.6.1
Pygments==2.0.1
chardet==2.3.0
colorama==0.3.2
docutils==0.12
html5lib==0.999
kazam==1.4.5
pygobject==3.14.0
python-apt==0.9.3.12
python-debian==0.1.27
pyxdg==0.25
requests==2.4.3
roman==2.0.0
six==1.8.0
urllib3==1.9.1
wheel==0.24.0

I've also tried uninstalling Kivy, amongst other things (trying to be cautious here, don't want to remove vital OS packages) but get the following output:

$ pip uninstall kivy 
Not uninstalling Kivy at /usr/lib/python3/dist-packages, owned by OS

So my questions is this: How can I get my python packages back to default, with only the essential system packages installed (almost like a fresh python install), then how do I prevent the requirements.txt files inside of a virtualenv including the system wide installed packages (I'll be using evn's much better in future so shouldn't have too many system wide packages)

I'd also be interested to find out why pip unistall kivy doesnt work (yes, I've tried running this as root also)

Running Debian 8, if that makes any difference

Hope this makes sense and appreciate any advise you may have.

EDIT: So I think I've been doing this whole thing wrong, once I've created the env I've been using pip install rather than env/bin/pip install . Unless I'm mistaken this is why the packages have been installing globally. Same goes for the requirements file.

您可以使用-l (或--local )参数冻结每个virtualenv中的本地包

pip freeze --local > requirements.txt 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM