我正在使用virtualenvwrapper启动一个新的Django项目,由于某些原因,django-admin无法识别我的设置模块:
$ mkproject djangotest
(djangotest) $ pip install Django
Collecting Django
Using cached Django-2.0-py3-none-any.whl
Collecting pytz (from Django)
Using cached pytz-2017.3-py2.py3-none-any.whl
Installing collected packages: pytz, Django
Successfully installed Django-2.0 pytz-2017.3
(djangotest) $ django-admin
以上命令有效,并为我提供了django-admin子命令的菜单。但是,当我尝试设置DJANGO_SETTINGS_MODULE时,我的新djangotest应用程序无法识别:
(djangotest) $ cd ../
(djangotest) $ django-admin startproject djangotest
(djangotest) $ cd djangotest
(djangotest) $ ls
djangotest manage.py
(djangotest) $ export DJANGO_SETTINGS_MODULE=djangotest.settings
(djangotest) $ django-admin
Traceback (most recent call last):
File "/Users/sam/Dropbox/.virtualenvs/djangotest/bin/django-admin", line 11, in <module>
sys.exit(execute_from_command_line())
File "/Users/sam/Dropbox/.virtualenvs/djangotest/lib/python3.6/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
utility.execute()
File "/Users/sam/Dropbox/.virtualenvs/djangotest/lib/python3.6/site-packages/django/core/management/__init__.py", line 317, in execute
settings.INSTALLED_APPS
File "/Users/sam/Dropbox/.virtualenvs/djangotest/lib/python3.6/site-packages/django/conf/__init__.py", line 56, in __getattr__
self._setup(name)
File "/Users/sam/Dropbox/.virtualenvs/djangotest/lib/python3.6/site-packages/django/conf/__init__.py", line 43, in _setup
self._wrapped = Settings(settings_module)
File "/Users/sam/Dropbox/.virtualenvs/djangotest/lib/python3.6/site-packages/django/conf/__init__.py", line 106, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/Users/sam/Dropbox/.virtualenvs/djangotest/lib/python3.6/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 'djangotest'
任何想法为什么&#39; djangotest&#39;模块没有找到?
答案 0 :(得分:1)
我有同样的问题。事实证明,当我运行manage.py命令时,我需要进入应用程序。