【问题标题】:Changing package install order in Python在 Python 中更改包安装顺序
【发布时间】:2012-08-03 03:02:12
【问题描述】:

有谁知道包安装顺序在 Python 中是否重要?更具体地说,我正在构建的 Django 网站的 pip requirements.txt 是:

Django==1.4
MySQL-python==1.2.3
django-evolution==0.6.7
django-pagination==1.0.7
boto==2.5.2
numpy==1.6.2
requests==0.13.1
simplejson==2.5.2
gunicorn==0.14.6

部署到 Heroku 时,应用程序会崩溃并出现以下错误:

2012-08-05T09:26:56+00:00 app[web.1]: 2012-08-05 09:26:56 [12] [INFO] Worker exiting (pid: 12)
2012-08-05T09:26:56+00:00 app[web.1]: 2012-08-05 09:26:56 [8] [INFO] Worker exiting (pid: 8)
2012-08-05T09:26:56+00:00 app[web.1]: 2012-08-05 09:26:56 [4] [INFO] Handling signal: term
2012-08-05T09:26:56+00:00 app[web.1]: 2012-08-05 09:26:56 [7] [INFO] Worker exiting (pid: 7)
2012-08-05T09:26:56+00:00 app[web.1]: 2012-08-05 09:26:56 [4] [INFO] Starting gunicorn 0.14.6
2012-08-05T09:26:56+00:00 app[web.1]: 2012-08-05 09:26:56 [4] [INFO] Listening at: http://0.0.0.0:20132 (4)
2012-08-05T09:26:56+00:00 app[web.1]: 2012-08-05 09:26:56 [4] [INFO] Using worker: sync
2012-08-05T09:26:56+00:00 app[web.1]: 2012-08-05 09:26:56 [7] [INFO] Booting worker with pid: 7
2012-08-05T09:26:56+00:00 app[web.1]: 2012-08-05 09:26:56 [8] [INFO] Booting worker with pid: 8
2012-08-05T09:26:56+00:00 app[web.1]: 2012-08-05 09:26:56 [9] [INFO] Booting worker with pid: 9
2012-08-05T09:26:56+00:00 app[web.1]: 2012-08-05 09:26:56 [10] [INFO] Booting worker with pid: 10
2012-08-05T09:26:57+00:00 heroku[web.1]: State changed from starting to up
2012-08-05T09:26:57+00:00 heroku[web.1]: Process exited with status 143
2012-08-05T09:27:17+00:00 app[web.1]: Usage: gunicorn [options]
2012-08-05T09:27:17+00:00 app[web.1]: gunicorn: error: no such option: --workers
2012-08-05T09:27:17+00:00 app[web.1]: 
2012-08-05T09:27:17+00:00 app[web.1]: 2012-08-05 09:27:17 [9] [INFO] Worker exiting (pid: 9)

这里我的Procfile如下:

web: python manage.py collectstatic --noinput; gunicorn commerical_production.wsgi:application --workers=4 --bind=0.0.0.0:$PORT

只需将需求顺序更改为:

Django==1.4
gunicorn==0.14.6
MySQL-python==1.2.3
django-evolution==0.6.7
django-pagination==1.0.7
boto==2.5.2
numpy==1.6.2
requests==0.13.1
simplejson==2.5.2

(注意gunicorn 现在移到了顶部)

我很幸运地猜测尝试更改导入的顺序,但我的问题是有没有其他人遇到过这个问题,或者知道为什么从requirements.txt 安装包的顺序会有所不同?这个问题是否表明我的应用程序中存在一些更大的依赖问题?

【问题讨论】:

  • 这通常无关紧要,因为在允许应用程序运行之前必须安装所有内容。不确定 heroku 是否在做不同的事情。

标签: python django heroku dependencies pip


【解决方案1】:

Pip 不像 easy_install 那样擅长处理包依赖关系。我们在项目中遇到了同样的问题。即使 req.txt 中的顺序是正确的,我们还是遇到了与顺序相关的依赖问题。

我的解决方案是将 req.txt 提供给 easy_install,但你应该小心可编辑的包或来自 github 等的包。

您可能需要查看以下链接:

http://metak4ml.blogspot.com/2009/08/easyinstall-read-pip-requirementstxt.html http://community.webfaction.com/questions/1220/using-easy_install-to-get-all-dependencies-listed-in-requirementstxt (而阅读行答案与我们所做的接近)

【讨论】:

    【解决方案2】:

    Pyton 设置安装脚本已经包含要求和顺序,因此安装过程将尊重并按照要求文件中每个应用的所有要求进行安装。

    因此,如果您有自己的应用程序需要其他应用程序,请将您的要求仅放在您的设置文件中,并将您的主应用程序注册到 requirements.txt 中

    对于不需要编译的第三方 python 应用程序,您不必担心需求中的顺序。

    否则 eazy_install 将被弃用,请使用 pip 代替它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-09-15
      • 2016-09-26
      • 2013-03-08
      • 2016-04-20
      • 2014-05-05
      • 1970-01-01
      • 2018-05-23
      相关资源
      最近更新 更多