【问题标题】:Installing scikit-learn and scipy on elastic beanstalk with pip and requirements.txt使用 pip 和 requirements.txt 在弹性 beantalk 上安装 scikit-learn 和 scipy
【发布时间】:2016-02-21 17:54:27
【问题描述】:

在部署到弹性 beanstalk 时,我不断收到错误:

Partial import of sklearn during the build process.
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "/tmp/pip-build-Le610u/scikit-learn/setup.py", line 247, in <module>
      setup_package()
    File "/tmp/pip-build-Le610u/scikit-learn/setup.py", line 237, in setup_package
      .format(scipy_req_str, instructions))
  ImportError: Scientific Python (SciPy) is not installed.
  scikit-learn requires SciPy >= 0.9.
  Installation instructions are available on the scikit-learn website: http://scikit-learn.org/stable/install.html

我的 requirements.txt 中同时包含 scikit-learn 和 scipy。

为什么会这样?我不想手动安装软件包,并且给人的印象是 pip 会为我整理安装顺序(它目前正在尝试在 scipy 之前安装 scikit-learn)。可能值得注意的是,相同的 requirements.txt 在我的本地计算机上运行良好。

我能做些什么来解决这个问题?

编辑:如果我更改 requirements.txt 中条目的顺序,使 scipy 高于 scikit-learn,它就可以正常工作。我仍然想知道为什么这会反过来失败,因为 pip freeze > requirements.txt 会用字母顺序覆盖它。

【问题讨论】:

标签: python amazon-web-services pip


【解决方案1】:

Requirements files 是包含要使用pip 安装的项目列表的文件:

从逻辑上讲,Requirements 文件只是放置在文件中的 pip install 参数列表。

因此,您的requirements.txt 中的条目将由 pip 顺序处理。现在,pip doesn't have true dependency resolution 和 scipy 在其 setup.py 中缺少正确的 install_requires,您必须先告诉 pip install scipy。 (如果您有兴趣,请参阅"setup.py vs requirements.txt" by Donald Stufft

相同的requirements.txt 在您的本地计算机上工作的原因可能是您在运行脚本之前安装了 scipy。您可以通过virtualenv 在您的计算机上创建一个干净的python 环境并再次运行该脚本来验证这一点。

【讨论】:

  • 感谢乔恩的回答和链接。解决此问题的唯一方法是“手动”修复 requirements.txt 的顺序,还是您能推荐另一种我可以做到的方法?
  • @krishan711 我找不到任何好的解决方案来自动修复订单。你可以试试conda而不是pip,这是一个cross-platform, Python-agnostic binary package manager
猜你喜欢
  • 2017-03-08
  • 2021-10-07
  • 1970-01-01
  • 1970-01-01
  • 2012-11-02
  • 2021-02-13
  • 2012-12-31
  • 2012-06-22
  • 2018-06-19
相关资源
最近更新 更多