Question

This is what my directory structure looks like (I've included only the relevant parts):

my_git_root/
├── Procfile
├── README.md
├── requirements.txt
└── my_django_project
    ├── app1
    │   ├── admin.py
    │   ├── __init__.py
    │   ├── models.py
    │   ├── tests.py
    │   ├── urls.py
    │   └── views.py
    ├── fabfile.py
    ├── app2
    │   ├── __init__.py
    │   ├── models.py
    │   ├── templates
    │   ├── tests.py
    │   └── views.py
    ├── manage.py
    └── my_django_project
        ├── __init__.py
        ├── settings
        │   ├── base.py
        │   ├── __init__.py
        │   ├── local.py
        │   ├── production.py
        │   └── staging.py
        ├── static
        ├── urls.py
        └── wsgi.py

Following the official Heroku docs, here's what I have in my Procfile:

web: gunicorn my_django_project.wsgi

But when I run the foreman start, command, I get a long traceback that ends with ImportError: No module named my_django_project.wsgi..

Moving Procfile from git_root/ to my_django_project/ (the Django project root) seems to work (like what was done in this post), but only locally -- attempting to deploy to Heroku seems to be ok, until you try to scale the web processes:

$ heroku ps:scale web=1
Scaling web dynos... failed 
 !    No such process type web defined in Procfile. 

It would appear as though Heroku wants you to put the Procfile in the project's git repository root, but I've tried lots of combinations in Procfile and none seem to work. I've also tried:

web: gunicorn my_django_project/my_django_project.wsgi

in the Procfile but that results in ImportError: Import by filename is not supported.

Specifying the python path doesn't work either; i.e.

web: gunicorn my_django_project.wsgi:application --pythonpath=/app/my_django_project

throws the error ImportError: No module named my_django_project.wsgi.

However, running locally with gunicorn from git_root/my_django_project/ seems to work:

$ gunicorn -b 0.0.0.0:8000 my_django_project.wsgi:application            
2013-10-15 16:55:31 [5703] [INFO] Starting gunicorn 18.0
2013-10-15 16:55:31 [5703] [INFO] Listening at: http://0.0.0.0:8000 (5703)
2013-10-15 16:55:31 [5703] [INFO] Using worker: sync
2013-10-15 16:55:31 [5708] [INFO] Booting worker with pid: 5708
2013-10-15 16:56:04 [5703] [INFO] Handling signal: winch
2013-10-15 16:56:04 [5703] [INFO] SIGWINCH ignored. Not daemonized

So my guess is that the syntax in my Procfile is incorrect, but I'm not sure how.

Was it helpful?

Solution

Figured it out while writing this question!

What I had to do was set the --pythonpath option to point to my django project root, i.e. git_root/my_django_project/.

This is what I had in my Procfile:

web: gunicorn -b 0.0.0.0:8000 --pythonpath=./my_django_project my_django_project.wsgi:application

Now it works locally:

$ foreman start
17:04:02 web.1  | started with pid 6327
17:04:02 web.1  | 2013-10-15 17:04:02 [6330] [INFO] Starting gunicorn 18.0
17:04:02 web.1  | 2013-10-15 17:04:02 [6330] [INFO] Listening at: http://0.0.0.0:8000 (6330)
17:04:02 web.1  | 2013-10-15 17:04:02 [6330] [INFO] Using worker: sync
17:04:02 web.1  | 2013-10-15 17:04:02 [6335] [INFO] Booting worker with pid: 6335
17:04:04 web.1  | 2013-10-15 17:04:04 [6330] [INFO] Handling signal: winch
17:04:04 web.1  | 2013-10-15 17:04:04 [6330] [INFO] SIGWINCH ignored. Not daemonized

And scaling web processes works now, too:

$ heroku ps:scale web=1 --app my-django-project                          
Scaling web dynos... done, now running 1

OTHER TIPS

Using your first scaffolding, where your Procfile is to the same level of my_django_project. I did this:

web: cd my_django_project && gunicorn my_django_project.wsgi --log-file -

Hope this helps.

--EDIT--

It's better change this file with the line bellow. Make sure you are on your master branch (I struggle with heroku pushing from another branch).

web: gunicorn --pythonpath my_django_project my_django_project.wsgi --log-file -

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top