【问题标题】:Installing a Module on Heroku在 Heroku 上安装模块
【发布时间】:2012-02-17 09:56:53
【问题描述】:

我正在部署一些已经在本地运行的东西,当我部署时意识到我正在使用的模块没有安装在 Heroku 上,因此我收到如下错误:

...
    from PIL import Image
ImportError: No module named PIL

我试过了:

heroku run pip install PIL

但我明白了:

ImportError: No module named setuptools.command

编辑

所以,我去了heroku setup 并模仿安装django 和postgres 的步骤。本质上,我激活了环境,然后运行了

pip install PIL

这似乎起到了作用,我得到了很多读数,然后以确认 PIL 已安装结束。但话又说回来,当我运行新文件时它说找不到 PIL。

【问题讨论】:

    标签: django module heroku python-imaging-library pip


    【解决方案1】:

    您在 Heroku 上运行的每个命令都在一个隔离且短暂的环境中运行 — 您在 heroku run 期间所做的任何更改都会在进程完成后立即丢弃。

    要使 PIL 可用于您的应用程序,您需要将其添加到 requirements.txt。

    【讨论】:

      【解决方案2】:

      有时 PIL 包会添加到您的路径中,但它位于 site-packages 之外的其他位置。在这种情况下,您将只能import Image。

      为了确保尝试这样的事情:

      >>> import sys
      >>> sys.path
      [(...), '/usr/lib/python2.7/dist-packages/PIL', (...)]
      >>> from PIL import Image
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
      ImportError: No module named PIL
      >>> import Image
      >>> Image
      <module 'Image' from '/usr/lib/python2.7/dist-packages/PIL/Image.pyc'>
      

      在我的应用程序中,我使用如下代码:

      try:
          import Image, ImageDraw, ImageFont
      except:
          from PIL import Image, ImageDraw, ImageFont
      

      【讨论】:

      • 我只是试了一下,还是找不到模块:from PIL import Image, ImageDraw, ImageFont ImportError: No module named PIL
      【解决方案3】:

      您确定您已关注http://devcenter.heroku.com/articles/django#prerequisites 并且您的 virtualenv 已加载?

      顺便说一句,我建议使用 Pillow 而不是 PIL。

      简介

      fork 作者的目标是通过以下方式促进包装改进:

      公开开发和征求社区支持。 探索分叉中的包装问题,最明显的是通过 添加 setuptools 支持,但也通过清理和重构 包装代码。为什么是叉子?

      PIL 当前与 setuptools 不兼容。请参见 http://mail.python.org/pipermail/image-sig/2010-August/006480.html 为 更详细的解释。此外,PIL 当前的发布/维护 时间表与各种频繁的包装不兼容 已经发生的问题。

      【讨论】:

      • 是的,heroku 方面一切正常,直到我添加了一个需要 PIL 的文件。
      【解决方案4】:

      即使我面临同样的问题,我也花了很多时间。

      我试过了

      heroku run pip install PIL --app=your-app

      错误:

      Running `pip install PIL` attached to terminal... up, run.1983
      Downloading/unpacking PIL
        Could not find any downloads that satisfy the requirement PIL
        Some externally hosted files were ignored (use --allow-external PIL to allow).
      Cleaning up...
      No distributions at all found for PIL
      Storing debug log for failure in /app/.pip/pip.log
      

      但这很有帮助:)

      heroku run pip install Pillow --app=your-app

      【讨论】:

        猜你喜欢
        • 2020-09-13
        • 1970-01-01
        • 2020-06-14
        • 2022-07-06
        • 2022-10-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多