我尝试为 Django 类(class)配置我的 PC,我有新的 Ubuntu 18.04:
我遵循了类(class)中的所有步骤:
我预装了最新的 python,Python 3.6.5,所以我去了:
sudo apt install python3-pip
一切顺利,然后:
pip3 install django==2.0.2 (version suggested by instructor)
也完成了,然后:
django-admin startproject wordcount
这给了我错误:
Command 'django-admin' not found, but can be installed with:
sudo apt install python-django-common
所以我尝试安装它,但没有帮助。所以我在网上查了答案,我发现我应该这样做:
sudo apt-get install python-django
然后我可以使用
django-admin startproject wordcount
它为我创建了一个项目,但我看到默认文件的某些元素与我在类(class)视频中看到的不同,所以我检查并:
django-admin --version
1.11.11
还有 django-admin --help
给我这样的消息:
Note that only Django core commands are listed as settings are not properly configured (error: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.).
有什么问题吗?我该如何解决?
最佳答案
问题是 pip3 安装的包由于某种原因不在 PATH 上。有几种方法可以解决这个问题。
将 pip3 安装位置添加到您的
$PATH
。强制它使用您通过 pip3 安装的 Django 版本:
$ python3 -m django.bin.django-admin startproject wordcount
使用 virtualenv 或 pipenv 创建“虚拟”Python 安装 - 完成它自己的 Python 版本和一组库。
关于python - django-admin 版本应该与 Django 相同吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51001773/