简体   繁体   English

pip freeze> requirements.txt包括virtualenv中所有系统安装的软件包

[英]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. 有点背景故事,我对Python和开发一般都比较陌生,并且愚蠢地将项目特定的软件包安装为系统软件包。 This is now causing me issues when trying to create requirements.txt files for specific projects, inside of virtualenvs. 现在,在virtualenvs内部尝试为特定项目创建requirements.txt文件时,这会引起我的问​​题。

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): 例如,我已经安装了Kivy系统,每次我创建一个带有需求文件的新环境时我都会得到以下内容(是的,env是活动的):

$ 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: 我还尝试卸载Kivy,其中包括(试图在这里谨慎,不想删除重要的操作系统包),但得到以下输出:

$ 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) 所以我的问题是这样的:我如何将我的python包恢复到默认状态,只安装了必要的系统包(几乎就像一个新的python安装),那么如何防止virtualenv中的requirements.txt文件包括系统广泛安装的软件包(我将来会更好地使用evn,所以不应该有太多系统范围的软件包)

I'd also be interested to find out why pip unistall kivy doesnt work (yes, I've tried running this as root also) 我也有兴趣找出为什么pip unistall kivy不起作用(是的,我也试过以root身份运行它)

Running Debian 8, if that makes any difference 运行Debian 8,如果这有任何区别

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 . 编辑:所以我认为我做错了这一切,一旦我创建了env我一直在使用pip install而不是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 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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