6

Trying to deploy my app with this tutorial. Have a ModuleNotFoundError: No module named 'radio.wsgi' message.

2019-08-21T08:08:21.409841+00:00 app[web.1]: __import__(module)
2019-08-21T08:08:21.409849+00:00 app[web.1]: ModuleNotFoundError: No module named 'radio.wsgi'
2019-08-21T08:08:21.409960+00:00 app[web.1]: [2019-08-21 08:08:21 +0000] [10] [INFO] Worker exiting (pid: 10)
2019-08-21T08:08:21.441211+00:00 app[web.1]: [2019-08-21 08:08:21 +0000] [4] [INFO] Shutting down: Master
2019-08-21T08:08:21.441415+00:00 app[web.1]: [2019-08-21 08:08:21 +0000] [4] [INFO] Reason: Worker failed to boot.

In some other questions people recomends python manage.py run_gunicorn but I have Unknown command: 'run_gunicorn'

Procfile:

web: gunicorn radio.wsgi --log-file -

wsgi.py

import os
from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'radio.settings')
application = get_wsgi_application()

In only those files WSGI is mentioned.

requirements.txt

dj-database-url==0.5.0
Django==2.2.4
gunicorn==19.9.0
lxml==4.4.1
psycopg2-binary==2.8.3
pytz==2019.2
sqlparse==0.3.0
whitenoise==4.1.3

This is project structure

├── radio
│   ├── db.sqlite3
│   ├── manage.py
│   ├── player
│   ├── radio
│   │   ├── __init__.py
│   │   ├── __pycache__
│   │   ├── settings.py
│   │   ├── urls.py
│   │   └── wsgi.py
│   ├── setup.py
│   └── static
├── README.md
├── .gitignore
├── requirements.txt
├── runtime.txt
└── Procfile
Pavel Antspovich
  • 1,111
  • 1
  • 11
  • 27
  • How about `mv Procfile radio/`? – Waket Zheng Aug 21 '19 at 08:40
  • 2
    If you look at the [tutorial source code](https://github.com/mdn/django-locallibrary-tutorial), you'll see that **Procfile**, **runtime.txt** and **requirements.txt** are all at the same level as **manage.py** which is the root of your project repository. – dirkgroten Aug 21 '19 at 08:44
  • @WaketZheng, nope. "No web processes running" – Pavel Antspovich Aug 21 '19 at 08:49
  • @dirkgroten, how can I restruct project like this? Цhen I initialized the player application it automatically placed here – Pavel Antspovich Aug 21 '19 at 08:56
  • What is "when I initialised the player application"? requirements.txt, runtime.txt, README.md... are all files you added manually in the wrong directory. Just move all these files inside your top `radio` directory. Actually, you probably did it wrong when initialising your git repository. `radio` should be the repository not the directory containing `radio`. – dirkgroten Aug 21 '19 at 08:59
  • On Heroku, the `Procfile` must be in the project root. You could move the contents of `radio` into the root directory (e.g. so `manage.py` is alongside `Procfile`), or you can [add the `radio` directory to the Python Path](https://stackoverflow.com/a/49459024/113962). – Alasdair Aug 21 '19 at 09:25
  • @WaketZheng moving `Procfile` won't work, because `Procfile` [must be in the project root](https://devcenter.heroku.com/articles/procfile#procfile-naming-and-location). – Alasdair Aug 21 '19 at 09:34

2 Answers2

9

Heroku expects Procfile to be in the project root. It is easiest to deploy a Django app if manage.py is in the project root as well. For example, if your project layout was:

├── db.sqlite3
├── manage.py
├── player
├── radio
│   ├── __init__.py
│   ├── __pycache__
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
├── setup.py
├── static
├── README.md
├── .gitignore
├── requirements.txt
├── runtime.txt
└── Procfile

then you can run:

web: gunicorn radio.wsgi

In your case, your Django project is in the radio directoy. If you don't want to change the project layout, then you need to add radio to the python path so that python imports work:

web: gunicorn --pythonpath radio radio.wsgi
Alasdair
  • 298,606
  • 55
  • 578
  • 516
1

After login from terminal using heroku login by downloading Heroku CLI, you can deploy on heroku using git by following:

git init
git add .
heroku create <app_name> --region <region_name>
git commit -am "SOME MESSAGE"
heroku config:set DEBUG_COLLECTSTATIC=1
heroku ps:scale web=1    // (optional)
git push heroku master

The ideal project structure shuold be like this...

   radio
   ├── db.sqlite3
   ├── manage.py
   ├── player
   ├── radio
   │   ├── __init__.py
   │   ├── settings.py
   │   ├── urls.py
   │   └── wsgi.py
   ├── setup.py
   ├── static
   ├── README.md
   ├── requirements.txt
   ├── runtime.txt
   └── Procfile
Bubai
  • 1,155
  • 1
  • 10
  • 20