我的设置是: - 安装了自制软件的Mac OS运行pyenv - python 3.6.5 virtualenv - pip install Django == 2.0.6
这是我发出的命令和输出。我在搜索时发现的唯一答案是假设现有的django项目和错误的配置。我无法达到创建项目的目的。
$ django-admin startproject justatestproj
Traceback (most recent call last):
File "/Users/rsquire/.pyenv/versions/forever7pi/bin/django-admin", line 11, in <module>
sys.exit(execute_from_command_line())
File "/Users/rsquire/.pyenv/versions/3.6.5/envs/forever7pi/lib/python3.6/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
utility.execute()
File "/Users/rsquire/.pyenv/versions/3.6.5/envs/forever7pi/lib/python3.6/site-packages/django/core/management/__init__.py", line 317, in execute
settings.INSTALLED_APPS
File "/Users/rsquire/.pyenv/versions/3.6.5/envs/forever7pi/lib/python3.6/site-packages/django/conf/__init__.py", line 56, in __getattr__
self._setup(name)
File "/Users/rsquire/.pyenv/versions/3.6.5/envs/forever7pi/lib/python3.6/site-packages/django/conf/__init__.py", line 43, in _setup
self._wrapped = Settings(settings_module)
File "/Users/rsquire/.pyenv/versions/3.6.5/envs/forever7pi/lib/python3.6/site-packages/django/conf/__init__.py", line 106, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/Users/rsquire/.pyenv/versions/3.6.5/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 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 'config'
顺便说一句,我在尝试时遇到同样的错误:
python -m django --version
但是,以下工作:
$ python
Python 3.6.5 (default, Apr 26 2018, 11:45:15)
[GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> print(django.get_version())
2.0.6
非常感谢任何建议!
答案 0 :(得分:1)
检查环境变量DJANGO_SETTINGS_MODULE
是否已设置,如果是,则取消设置。例如。在bash中
$ unset DJANGO_SETTINGS_MODULE
答案 1 :(得分:0)
对于 Windows 用户,请在命令行上尝试:
set DJANGO_SETTINGS_MODULE=