Rails 应用内的 Heroku 调度程序的 Python 脚本中没有名为 sendgrid 的模块

No module named sendgrid in Python script in Heroku scheduler inside Rails app

我已经在 Heroku 上部署了一个 Rails 应用程序。 Rails bin 文件夹中还有一个 Python 脚本。我现在使用 Heroku 调度程序每 10 分钟 运行 Python 脚本。我想先测试一下。所以我 运行:

heroku run python bin/notify.py

在我的本地终端。然后我收到以下错误消息:

Running python bin/notify.py on ...
Traceback (most recent call last):
  File "bin/notify.py", line 6, in <module>
    import sendgrid
ImportError: No module named sendgrid

但是,我已经在 Heroku 上安装了 sendgrid 插件。我也可以在我的 Rails 代码中使用 sendgrid,没有任何问题。

谁能帮我解决这个问题?谢谢!

我联系了 Heroku 技术支持。他们告诉我,我必须同时安装 ruby 和 python buildpack,并将 sendgrid 包含在应用程序根目录的 requirements.txt 中。

https://devcenter.heroku.com/articles/using-multiple-buildpacks-for-an-app

问题已解决。

听起来您忘记安装 Python's sendgrid dependency when building the container. See declare Python app dependencies 如何安装 Python 依赖项。由于您是 运行,ruby 和 Python,您必须安装两个构建包以确保加载两个依赖项。