django-configurations icon indicating copy to clipboard operation
django-configurations copied to clipboard

AttributeError: 'ConfigurationImporter' object has no attribute 'find_spec'

Open pas-marcus opened this issue 6 years ago • 8 comments

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.

pas-marcus avatar Mar 05 '19 17:03 pas-marcus

I get this too under docker

martyzz1 avatar Mar 12 '19 23:03 martyzz1

When using Docker already, could you specify a Dockerfile maybe to reproduce it?

blueyed avatar Mar 13 '19 00:03 blueyed

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].```

martyzz1 avatar Jul 08 '19 16:07 martyzz1

You can have this error with wrong module name: ./manage.py collectstatic --noinput --settings=wrong_settings_module

ram0973 avatar Sep 23 '19 12:09 ram0973

So that's about a namespace path, basically a Python package without a __init__.py?

jezdez avatar Dec 03 '19 12:12 jezdez

@jezdez Your suggestion fixed my error. I removed an __init__.py. Adding it back in solved my issue.

agconti avatar Jan 14 '20 23:01 agconti

moving to importlib instead of deprecated imp might solve this. effort tracked by #190

ticosax avatar Mar 18 '20 17:03 ticosax

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.

john-sandall avatar Dec 22 '21 17:12 john-sandall