Search code examples
pythondokkupython-poetry

Predeploy command fails on dokku


My app.json looks like this

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

And it gives this error

 !     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?

Not sure what to try out more to be honest.


Solution

  • What you're seeing is that the virtualenv isn't activated. Which is weird since poetry should handle that.

    However, for one, heroku doesn't support poetry.

    You can use this buildpack: https://elements.heroku.com/buildpacks/moneymeets/python-poetry-buildpack

    According to the docs, a collectstatic should happen automatically during a deploy: https://devcenter.heroku.com/articles/django-assets#collectstatic-during-builds

    And lastly: the poetry buildpack only creates a requirements.txt that is then installed with pip by the reqular heroku python buildpack.