django-configurations
django-configurations copied to clipboard
AttributeError: 'ConfigurationImporter' object has no attribute 'find_spec'
I am trying to add django-configurations to a basic Django project that runs in Docker. However, I get the following error. I've followed the installation instructions and confirmed my setup. Any thoughts on how to resolve this?
$ docker-compose run api python manage.py check
Creating network "myproject_default" with the default driver
Creating myproject_db_1 ... done
Traceback (most recent call last):
File "<frozen importlib._bootstrap>", line 888, in _find_spec
AttributeError: 'ConfigurationImporter' object has no attribute 'find_spec'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 325, in execute
settings.INSTALLED_APPS
File "/usr/local/lib/python3.6/site-packages/django/conf/__init__.py", line 57, in __getattr__
self._setup(name)
File "/usr/local/lib/python3.6/site-packages/django/conf/__init__.py", line 44, in _setup
self._wrapped = Settings(settings_module)
File "/usr/local/lib/python3.6/site-packages/django/conf/__init__.py", line 107, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/local/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 951, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 890, in _find_spec
File "<frozen importlib._bootstrap>", line 864, in _find_spec_legacy
File "/usr/local/lib/python3.6/site-packages/configurations/importer.py", line 139, in find_module
imp.find_module(module, path))
File "/usr/local/lib/python3.6/imp.py", line 271, in find_module
"not {}".format(type(path)))
RuntimeError: 'path' must be None or a list, not <class '_frozen_importlib_external._NamespacePath'>
Fatal error: local() encountered an error (return code 1) while executing 'docker-compose run api python manage.py check'
Aborting.
I get this too under docker
When using Docker already, could you specify a Dockerfile maybe to reproduce it?
I think this is due to a comment I've found here
https://www.python.org/dev/peps/pep-0420/#find-module-versus-find-loader
However, this caused a problem with existing code outside of the standard library which calls find_module. Because this code would not be upgraded in concert with changes required by this PEP, it would fail when it would receive unexpected return values from find_module. Because of this incompatibility, this PEP now specifies that finders that want to provide namespace portions must implement the find_loader method, described above.
The use case for supporting multiple portions per find_loader call is given in [7].```
You can have this error with wrong module name:
./manage.py collectstatic --noinput --settings=wrong_settings_module
So that's about a namespace path, basically a Python package without a __init__.py?
@jezdez Your suggestion fixed my error. I removed an __init__.py. Adding it back in solved my issue.
moving to importlib instead of deprecated imp might solve this.
effort tracked by #190
I was hitting this exact issue, the root cause was I needed to specify a mypy_path in mypy settings, I've documented this solution here.