decapo
decapo

Reputation: 839

Gunicorn ImportError: No module name app only when directory name is site

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?

Upvotes: 3

Views: 884

Answers (1)

melchoir55
melchoir55

Reputation: 7286

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.

Upvotes: 3

Related Questions