Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gunicorn Import by filename is not supported (module)

I have newly created a container ubuntu and installed the required packages in the virtual environment. Then I have executed the pre-existing python service code by python path/to/my/file/X.py (in virualenv) it's working fine. So I have executed with gunicorn as gunicorn -b 0.0.0.0:5000 path/to/my/file/X:app (in virualenv) but I'm getting the following error

2015-11-11 16:38:08 [19118] [INFO] Starting gunicorn 17.5
2015-11-11 16:38:08 [19118] [INFO] Listening at: http://0.0.0.0:444 (19118)
2015-11-11 16:38:08 [19118] [INFO] Using worker: sync
2015-11-11 16:38:08 [19123] [INFO] Booting worker with pid: 19123
2015-11-11 16:38:08 [19123] [ERROR] Exception in worker process:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/gunicorn/arbiter.py", line 473, in spawn_worker
    worker.init_process()
  File "/usr/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 100, in init_process
    self.wsgi = self.app.wsgi()
  File "/usr/lib/python2.7/dist-packages/gunicorn/app/base.py", line 115, in wsgi
    self.callable = self.load()
  File "/usr/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 33, in load
    return util.import_app(self.app_uri)
  File "/usr/lib/python2.7/dist-packages/gunicorn/util.py", line 362, in import_app
    __import__(module)
ImportError: Import by filename is not supported.
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/gunicorn/arbiter.py", line 473, in spawn_worker
    worker.init_process()
  File "/usr/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 100, in init_process
    self.wsgi = self.app.wsgi()
  File "/usr/lib/python2.7/dist-packages/gunicorn/app/base.py", line 115, in wsgi
    self.callable = self.load()
  File "/usr/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 33, in load
    return util.import_app(self.app_uri)
  File "/usr/lib/python2.7/dist-packages/gunicorn/util.py", line 362, in import_app
    __import__(module)
ImportError: Import by filename is not supported.
2015-11-11 16:38:08 [19123] [INFO] Worker exiting (pid: 19123)
2015-11-11 16:38:09 [19118] [INFO] Shutting down: Master

Can anyone help me fix the ImportError: Import by filename is not supported. Why it is coming? I have implemented gunicorn in other server, it is working fine there.

like image 723
gopinath Avatar asked Nov 11 '15 17:11

gopinath


1 Answers

I faced very same issue, I got it worked using --chdir /path/to/project

gunicorn -b :5000 --chdir /path/to/project X:app

Hope this helps

like image 69
Arun G Avatar answered Sep 24 '22 02:09

Arun G