使用 python manage.py runserver 正常启动,使用 django-admin 出错。查看 manage.py 中也是用的'Bill.settings',参考了 overflow 加了命令的参数还是不行,请教大家到底啥原因,如何解决
使用命令
django-admin runserver 8054 --settings="Bill.settings" --pythonpath=.
出现错误
(venv-django2.2) D:\PythonApp\Bill>django-admin runserver 8054 --settings="Bill.settings" --pythonpath="D:\Program Files\Python\Python36"
Traceback (most recent call last):
File "d:\pythonapp\venvs\venv-django2.2\lib\site-packages\django\core\management\base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "d:\pythonapp\venvs\venv-django2.2\lib\site-packages\django\core\management\commands\runserver.py", line 60, in execute
super().execute(*args, **options)
File "d:\pythonapp\venvs\venv-django2.2\lib\site-packages\django\core\management\base.py", line 364, in execute
output = self.handle(*args, **options)
File "d:\pythonapp\venvs\venv-django2.2\lib\site-packages\django\core\management\commands\runserver.py", line 67, in handle
if not settings.DEBUG and not settings.ALLOWED_HOSTS:
File "d:\pythonapp\venvs\venv-django2.2\lib\site-packages\django\conf\__init__.py", line 79, in __getattr__
self._setup(name)
File "d:\pythonapp\venvs\venv-django2.2\lib\site-packages\django\conf\__init__.py", line 66, in _setup
self._wrapped = Settings(settings_module)
File "d:\pythonapp\venvs\venv-django2.2\lib\site-packages\django\conf\__init__.py", line 157, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "D:\Program Files\Python\Python36\lib\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 941, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'Bill'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\Program Files\Python\Python36\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "D:\Program Files\Python\Python36\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "D:\PythonApp\venvs\venv-django2.2\Scripts\django-admin.exe\__main__.py", line 9, in <module>
File "d:\pythonapp\venvs\venv-django2.2\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "d:\pythonapp\venvs\venv-django2.2\lib\site-packages\django\core\management\__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "d:\pythonapp\venvs\venv-django2.2\lib\site-packages\django\core\management\base.py", line 336, in run_from_argv
connections.close_all()
File "d:\pythonapp\venvs\venv-django2.2\lib\site-packages\django\db\utils.py", line 219, in close_all
for alias in self:
File "d:\pythonapp\venvs\venv-django2.2\lib\site-packages\django\db\utils.py", line 213, in __iter__
return iter(self.databases)
File "d:\pythonapp\venvs\venv-django2.2\lib\site-packages\django\utils\functional.py", line 80, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "d:\pythonapp\venvs\venv-django2.2\lib\site-packages\django\db\utils.py", line 147, in databases
self._databases = settings.DATABASES
File "d:\pythonapp\venvs\venv-django2.2\lib\site-packages\django\conf\__init__.py", line 79, in __getattr__
self._setup(name)
File "d:\pythonapp\venvs\venv-django2.2\lib\site-packages\django\conf\__init__.py", line 66, in _setup
self._wrapped = Settings(settings_module)
File "d:\pythonapp\venvs\venv-django2.2\lib\site-packages\django\conf\__init__.py", line 157, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "D:\Program Files\Python\Python36\lib\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 941, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'Bill'
1
OnlyO 2020-06-28 17:15:25 +08:00
pythonpath 是你项目根文件夹, 你是不是路径没有添对,注意绝对路径和相对路径.
|
2
littlecrab OP @OnlyO 谢谢! 想当然地以为 pythonpath 是 python 路径,No module 的错误就是 pythonpath 配置错了造成的。pythonpath 设置成项目路径就可以了。
不过现在一直提示找不到 django-admin“d:\program files\python\python36\python.exe: can't open file 'D:\Program Files\Python\Python36\Scripts\django-admin': [Errno 2] No such file or directory” ,环境变量没问题,django-admin runserver 也能打印版本号,找到现在也没找到解决方法,请问这个问题您知道如何解决吗 |