Django / Python error. & Ldquo; ImportError: Import by filename is not supported. & Rdquo;

advertisements

I wanted to install Django and have troubles with the import error. I read this topic, but the answer didn't help here. Nothing happend after I changed the env variables to the module path.

C:\Users\M>django-admin.py
Traceback (most recent call last):
  File "C:\Python27\Scripts\django-admin.py", line 5, in <module>
    management.execute_from_command_line()
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 350, in execute_from_command_line
    utility.execute()
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 302, in execute
    settings.INSTALLED_APPS
  File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 55, in __getattr__
    self._setup(name)
  File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 43, in _setup
    self._wrapped = Settings(settings_module)
  File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 99, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "C:\Python27\lib\importlib\__init__.py", line 37, in import_module
    __import__(name)
ImportError: Import by filename is not supported.


DJANGO_SETTINGS_MODULE shouldn't be system path to settings file (or directory). It should be an python path to your settings file. So first, make sure that your project is in PYTHONPATH or you are inside project directory, then set correct DJANGO_SETTINGS_MODULE and after that, run your django-admin command.

You can also clean DJANGO_SETTINGS_MODULE variable if command that you're trying to issue is not related with existing django project.