V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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 · 2020-06-28 17:05:06 +08:00 · 1368 次点击
    这是一个创建于 1635 天前的主题,其中的信息可能已经有所发展或是发生改变。

    问题

    使用 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  
       2020-06-28 17:15:25 +08:00
    pythonpath 是你项目根文件夹, 你是不是路径没有添对,注意绝对路径和相对路径.
    littlecrab
        2
    littlecrab  
    OP
       2020-06-28 18:57:49 +08:00
    @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 也能打印版本号,找到现在也没找到解决方法,请问这个问题您知道如何解决吗
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   3391 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 11:11 · PVG 19:11 · LAX 03:11 · JFK 06:11
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.