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.
I was facing the same issue in windows. Then later I realised that the problem is with the version of Django installed. I am using python 2.7, and it seems that the import by filename is not supported by it. I believe if you use python 3 , there wont be any problem. So , I installed django 1.6.5 and the solved the problem.
pip install django==1.6.5
来源:https://stackoverflow.com/questions/34481102/django-python-error-importerror-import-by-filename-is-not-supported