首页 > 解决方案 > dokku 上的预部署命令失败

问题描述

我的 app.json 看起来像这样

{
    "scripts": {
      "dokku": {
        "predeploy": "poetry run python manage.py collectstatic --noinput && poetry run python manage.py migrate"
      }
    }
}

它给出了这个错误

 !     Predeploy command declared: 'poetry run python manage.py collectstatic --noinput && poetry run python manage.py migrate'
remote: execution of 'poetry run python manage.py collectstatic --noinput && poetry run python manage.py migrate' failed!
       Creating virtualenv foxflash-9TtSrW0h-py3.6 in /app/.cache/pypoetry/virtualenvs
       Traceback (most recent call last):
         File "manage.py", line 9, in main
           from django.core.management import execute_from_command_line
       ModuleNotFoundError: No module named 'django'
       The above exception was the direct cause of the following exception:
       Traceback (most recent call last):
         File "manage.py", line 20, in <module>
           main()
         File "manage.py", line 15, in main
           ) from exc
       ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?

老实说,不确定要尝试更多。

标签: pythondokkupython-poetry

解决方案


你看到的是 virtualenv 没有被激活。这很奇怪,因为诗歌应该处理这个问题。

然而,一方面,heroku 不支持诗歌。

您可以使用此构建包: https ://elements.heroku.com/buildpacks/moneymeets/python-poetry-buildpack

根据文档,collectstatic 应该在部署期间自动发生: https ://devcenter.heroku.com/articles/django-assets#collectstatic-during-builds

最后:poetry buildpack 只创建一个 requirements.txt,然后由 requular heroku python buildpack 与 pip 一起安装。


推荐阅读