3

Trying to get gunicorn runing with a hello world app.
This is my project directory structure

Project
  |_ config
  |  |_ ___init__.py
  |  |_ settings.py
  |
  |_ instance
  |  |_settings.py_production
  |
  |_ site
  |  |_ __init__.py
  |  |_ app.py
  |
  |_ .env
  |_ docker-compose.yml
  |_ Dockerfile
  |_ requirements.txt

I am running this in a docker container but when I go into the container in interactive mode the same behaviour occurs.

When the directory is named site and I run the command gunicorn -b 0.0.0.0:8000 --access-logfile - "site.app:create_app()" I get an error ImportError: No module name app. However if I name the directory foo, snakeeyes or blah I do not recieve an error and the app runs as expected. Is there a reason for this? Can directories not be named site? Are there any other restreicted direcory names in python?

decapo
  • 789
  • 3
  • 8
  • 25
  • You shouldn't call your module the same as any module which is a part of the Python standard library as depending on the ordering of the module import path, you will get the wrong one. – Graham Dumpleton May 20 '17 at 05:25

1 Answers1

3

site is part of the standard library in python. I assume, but am not positive, that you are experiencing a conflict.

site is not a reserved word in python . You can check out this SO post if you're interested in the standard keywords: Is the list of Python reserved words and builtins available in a library?

I think you might be able to test whether this is a conflict by suppressing the automatic import of the library as directed by the documentation:

This module is automatically imported during initialization. The automatic import can be suppressed using the interpreter’s -S option.
Community
  • 1
  • 1
melchoir55
  • 6,842
  • 7
  • 60
  • 106
  • running `gunicorn -S -b 0.0.0.0:8000 --access-logfile - "pickle.app:create_app()"` threw an error saying the -S wasn't a valid option. I did however take a look at the list here https://docs.python.org/3/contents.html under improved modules where site is located. I renamed everything to another module `pickle` and got the same `ImportError: No module named app` result. I beleve this is the correct answer. – decapo May 20 '17 at 14:41
  • Gunicorn isn't an interpreter of python. The documentation is referring to the actual call to python. So, something like `python -S`. If you wanted to try that experiment you would need to figure out how to pass command line arguments to the python interpreter through gunicorn. – melchoir55 May 20 '17 at 20:52