问题描述
我想安装Django并且有导入错误的麻烦。
我阅读了,但答案在这里没有帮助。将env变量更改为模块路径后,没有任何变化。
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
不应该是设置文件(或目录)的系统路径。它应该是您的设置文件的python路径。首先,确保您的项目位于 PYTHONPATH
或您在项目目录中,然后设置正确的 DJANGO_SETTINGS_MODULE
您可以执行 django-admin
命令。
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.
您还可以清除 DJANGO_SETTINGS_MODULE
变量,如果您要发出的命令与现有django项目无关。
You can also clean
DJANGO_SETTINGS_MODULE
variable if command that you're trying to issue is not related with existing django project.
这篇关于Django / Python错误。 “ImportError:不支持按文件名导入”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!