推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
littlecrab
V2EX  ›  Python

[Django 新手问题求教] Django2.2 使用 django-admin runserver 出现 No module named 'Bill'错误,但是使用 Python manage runserver 没问题。

  •  
  •   littlecrab · Jun 28, 2020 · 1975 views
  •   You need to sign in to view this topic
    This topic created in 2216 days ago, the information mentioned may be changed or developed.

    问题

    使用 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'
    
    
    OnlyO
        1
    OnlyO  
       Jun 28, 2020
    pythonpath 是你项目根文件夹, 你是不是路径没有添对,注意绝对路径和相对路径.
    littlecrab
        2
    littlecrab  
    OP
       Jun 28, 2020
    @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 也能打印版本号,找到现在也没找到解决方法,请问这个问题您知道如何解决吗
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5353 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 38ms · UTC 07:59 · PVG 15:59 · LAX 00:59 · JFK 03:59
    ♥ Do have faith in what you're doing.