从virtualenv,点击冻结> requirements.txt给予垃圾的TONES!如何修剪? [英] From virtualenv, pip freeze > requirements.txt give TONES of garbage! How to trim it out?

查看:169
本文介绍了从virtualenv,点击冻结> requirements.txt给予垃圾的TONES!如何修剪?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在关注本教程:
http://devcenter.heroku.com/articles / django



在某些时候,我被允许做:

 点击冻结> ($)



(Ofc。from virtualenv创建python实例)



我得到这个:

 (venv)przemoli @ ubuntu:〜/ Programowanie / hellodjango $ cat requirements.txt 
BeautifulSoup == 3.2.0
Brlapi == 0.5.5
CherryPy == 3.1.2
ClientForm == 0.2.10
Django == 1.3
GnuPGInterface == 0.3.2
PAM == 0.4.2
PIL == 1.1.7
路线== 1.12.3
Twisted-Core == 11.0.0
Twisted-Names == 11.0.0
Twisted-Web == 11.0.0
WebOb == 1.0.8
adium-theme-ubuntu == 0.3。 1
apt-xapian-index == 0.44
apturl == 0.5.1ubuntu1
chardet == 2.0.1
command-not-found == 0.2.44
configglue == 1.0
cssutils == 0.9.8a1
defer == 1.0.2
distribute == 0.6.19
django-tagging == 0.3.1
dnspython == 1.9.4
duplicateity == 0.6.15
gnome-app-install == 0.4.7-nmu1ubuntu2
httplib2 == 0.7.2
jockey == 0.9.4
keyring == 0.6.2
launchpadlib == 1.9.8
lazr.restfulclient == 0.11.2
lazr.uri == 1.0.2 $ b $ lo s == 2.3.0
lxml == 2.3
mechanize == 0.1.11
nvidia-common == 0.0.0
oauth == 1.0.1
onboard == 0.96.1
oneconf == 0.2.6.7
papyon == 0.5.5
pexpect == 2.3
活塞迷你客户端== 0.6
protobuf == 2.4.0a
psycopg2 == 2.4.4
pyOpenSSL == 0.12
pycrypto == 2.3
pycups == 1.9.59
pycurl == 7.19 .0
pyinotify == 0.9.1
pyparsing == 1.5.2
pyserial == 2.5
pysmbc == 1.0.10
python-apt == 0.8 .0ubuntu9
python-dateutil == 1.4.1
python-debian == 0.1.20ubuntu2
python-virtkey == 0.60.0
pyxdg == 0.19
sessioninstaller == 0.0.0
simplejson == 2.1.6
system-service == 0.1.6
ubuntu-sso-client == 1.4.0
ubuntuone-couch = = 0.3.0
ubuntuone-installer == 2.0.0
ubuntuone-storage-protocol == 2.0.0
ufw == 0.30.1-2ubuntu1
无人值守升级= = 0.1
usb-creator == 0.2.23
virtualenv == 1.6.4
wadllib == 1.2.0
wsgiref == 0.1.2
xdiagnose = = 1.1
xkit == 0.0.0
zope.interface == 3.6.1

当de我在ubuntu上的主要python安装中看到很多东西。 Ubuntu使用python本身就是一些BAD(ubuntu-one,usb-creator等)。



我不需要他们在heroku!我只需要Django,psycopg2及其依赖关系。
我甚至不知道它的漏洞,或virutalenv。 (如果你想知道我的设置看看上面的链接,我把它复制到终端)

解决方案

这是一个bug我太好了当您创建没有 - no-site-packages 标志的virtualenv时,会发生这种情况。



有一对您可以做的事情:


  1. 使用创建virtualenv - 无站点包标志。

  2. 安装应用程序时,不要直接运行 pip install< name> ,而是将库添加到 requirements.txt 首先,然后安装要求。这是较慢的,但确保您的要求更新。

  3. 手动删除不需要的库。我遵循的经验法则是在我的 INSTALLED_APPS 和数据库适配器中添加任何内容。大多数其他必需的库将因为依赖而自动安装。我知道它的愚蠢,但这是我通常最终做的。

- 编辑 -



我以前写过一个几本脚本帮助管理这个。第一个运行点冻结,并将找到的库添加到提供的需求文件中,另一个运行pip install,然后将其添加到需求文件中。

  function pipa(){
#将包添加到需求文件中。
#用法:pipa< package> <要求文件的路径>
package_name = $ 1
requirements_file = $ 2
if [[-z $ requirements_file]]
then
requirements_file ='。/ requirements.txt'
fi
package_string =`pip freeze | grep -i $ package_name`
current_requirements =`cat $ requirements_file`
echo$ current_requirements\\\
$ package_string| LANG = C sort | uniq> $ requirements_file
}

函数pipia(){
#安装包并添加到需求文件中。
#用法:pipia< package> <要求文件的路径>
package_name = $ 1
requirements_file = $ 2
if [[-z $ requirements_file]]
then
requirements_file ='。/ requirements.txt'
fi
pip install $ package_name
pipa $ package_name $ requirements_file
}


I'm following this tutorial: http://devcenter.heroku.com/articles/django

At some point I'm suposed to do:

pip freeze > requirements.txt

(Ofc. from virtualenv created instance of python)

And I get this:

(venv)przemoli@ubuntu:~/Programowanie/hellodjango$ cat requirements.txt 
BeautifulSoup==3.2.0
Brlapi==0.5.5
CherryPy==3.1.2
ClientForm==0.2.10
Django==1.3
GnuPGInterface==0.3.2
PAM==0.4.2
PIL==1.1.7
Routes==1.12.3
Twisted-Core==11.0.0
Twisted-Names==11.0.0
Twisted-Web==11.0.0
WebOb==1.0.8
adium-theme-ubuntu==0.3.1
apt-xapian-index==0.44
apturl==0.5.1ubuntu1
chardet==2.0.1
command-not-found==0.2.44
configglue==1.0
cssutils==0.9.8a1
defer==1.0.2
distribute==0.6.19
django-tagging==0.3.1
dnspython==1.9.4
duplicity==0.6.15
gnome-app-install==0.4.7-nmu1ubuntu2
httplib2==0.7.2
jockey==0.9.4
keyring==0.6.2
launchpadlib==1.9.8
lazr.restfulclient==0.11.2
lazr.uri==1.0.2
louis==2.3.0
lxml==2.3
mechanize==0.1.11
nvidia-common==0.0.0
oauth==1.0.1
onboard==0.96.1
oneconf==0.2.6.7
papyon==0.5.5
pexpect==2.3
piston-mini-client==0.6
protobuf==2.4.0a
psycopg2==2.4.4
pyOpenSSL==0.12
pycrypto==2.3
pycups==1.9.59
pycurl==7.19.0
pyinotify==0.9.1
pyparsing==1.5.2
pyserial==2.5
pysmbc==1.0.10
python-apt==0.8.0ubuntu9
python-dateutil==1.4.1
python-debian==0.1.20ubuntu2
python-virtkey==0.60.0
pyxdg==0.19
sessioninstaller==0.0.0
simplejson==2.1.6
system-service==0.1.6
ubuntu-sso-client==1.4.0
ubuntuone-couch==0.3.0
ubuntuone-installer==2.0.0
ubuntuone-storage-protocol==2.0.0
ufw==0.30.1-2ubuntu1
unattended-upgrades==0.1
usb-creator==0.2.23
virtualenv==1.6.4
wadllib==1.2.0
wsgiref==0.1.2
xdiagnose==1.1
xkit==0.0.0
zope.interface==3.6.1

When deploying on heroku it fails at Brlapi .....

I see lots of stuff from my main python installation which is on ubuntu. Which is BAD since Ubuntu use python for quite a few thing itself (ubuntu-one, usb-creator, etc..).

I do not need them on heroku! I need only Django, psycopg2, and their dependencies. I do not even know if its fault of pip, or virutalenv. (If you want to know my setup look at link above I copied it into terminal)

解决方案

That is one thing that has bugged me too quite a bit. This happens when you create a virtualenv without the --no-site-packages flag.

There are a couple of things you can do:

  1. Create virtualenv with the --no-site-packages flag.
  2. When installing apps, dont run pip install <name> directly, instead, add the library to your requirements.txt first, and then install the requirements. This is slower but makes sure your requirements are updated.
  3. Manually delete libraries you dont need. A rule of thumb i follow for this is to add whatever is there in my INSTALLED_APPS, and database adapters. Most other required libraries will get installed automatically because of dependencies. I know its silly, but this is what I usually end up doing.

-- Edit --

I've since written a couple of scripts to help manage this. The first runs pip freeze and adds the found library to a provided requirements file, the other, runs pip install, and then adds it to the requirements file.

function pipa() {
    # Adds package to requirements file.
    # Usage: pipa <package> <path to requirements file>
    package_name=$1
    requirements_file=$2
    if [[ -z $requirements_file ]]
    then
        requirements_file='./requirements.txt'
    fi
    package_string=`pip freeze | grep -i $package_name`
    current_requirements=`cat $requirements_file`
    echo "$current_requirements\n$package_string" | LANG=C sort | uniq > $requirements_file
}

function pipia() {
    # Installs package and adds to requirements file.
    # Usage: pipia <package> <path to requirements file>
    package_name=$1
    requirements_file=$2
    if [[ -z $requirements_file ]]
    then
        requirements_file='./requirements.txt'
    fi
    pip install $package_name
    pipa $package_name $requirements_file
}

这篇关于从virtualenv,点击冻结&gt; requirements.txt给予垃圾的TONES!如何修剪?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆