简体   繁体   English

django-admin版本应该与Django版本相同吗?

[英]Should django-admin version be same as Django?

I tried to configure my PC for Django course , i have fresh Ubuntu 18.04 : 我试图为Django课程配置PC,但我有新的Ubuntu 18.04:

I followed all steps from the course : 我遵循了课程中的所有步骤:

I had newest python pre-installed, Python 3.6.5 so i went : 我预先安装了最新的python,Python 3.6.5,所以我去了:

sudo apt install python3-pip

went ok, then : 一切顺利,然后:

pip3 install django==2.0.2 (version suggested by instructor)

that completed as well, then : 也完成了,然后:

django-admin startproject wordcount

and that gave me error : 这给了我错误:

Command 'django-admin' not found, but can be installed with:

sudo apt install python-django-common

So i tried to install this but it didn't help. 所以我试图安装它,但是没有帮助。 so i checked web for answers and i found that i should do : 所以我在网上检查了答案,发现应该这样做:

sudo apt-get install python-django

And after that i could use 在那之后我可以使用

django-admin startproject wordcount

and it created a project for me but i saw that some elements of default files are different from what i saw on course video so i check and : 它为我创建了一个项目,但我发现默认文件的某些元素与课程视频中看到的有所不同,因此我检查并:

django-admin --version
1.11.11

also django-admin --help 也是django-admin --help

gives me message like this : 给我这样的消息:

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.).

Any ideas what went wrong and how I can fix it? 任何想法出了什么问题,我该如何解决?

I see you struggle with this problem. 我看到你在为这个问题而苦苦挣扎。 I would recommend you to move to such thing as a virtualenv (or use anaconda for this task). 我建议您转到virtualenv类的东西(或使用anaconda进行此任务)。 This should solve a numerous other problems you've not ran across yet and this one especially. 这应该可以解决您尚未遇到的许多其他问题,尤其是这个问题。

Virtual environment allows you to create separate environment, with it's own packet set. 虚拟环境允许您使用自己的数据包集创建单独的环境。 Some IDEs (for example, pycharm) provide GUI for it's creation and management. 一些IDE(例如pycharm)为其创建和管理提供GUI。

Update 1: 更新1:

Thanks to @DhavalSavalia, of course there is also pipenv package, that is a more friendly virtualenv wrapper (unless you have some gui for virtualenv ). 感谢@DhavalSavalia,当然也有pipenv软件包,它是一个更友好的virtualenv包装器(除非您有virtualenv gui)。

Update 2: 更新2:

Also, I've noticed that you setting up django using apt. 另外,我注意到您使用apt设置了django。 You probably shouldn't do that, because apt often contains old version of python packages. 您可能不应该这样做,因为apt通常包含旧版本的python软件包。 Use pip for as many packages as you can. 尽可能将pip用于尽可能多的软件包。

The problem is that the pip3-installed packages aren't on the PATH for some reason. 问题是由于某些原因,安装了pip3的软件包不在PATH上。 There's a few ways to fix this. 有几种方法可以解决此问题。

  1. Add the pip3 installation location to your $PATH . 将pip3安装位置添加到$PATH
  2. Force it to use the version of Django you installed via pip3: 强制它使用通过pip3安装的Django版本:

    $ python3 -m django.bin.django-admin startproject wordcount

  3. Use virtualenv or pipenv to create a "virtual" Python installation - complete with it's own Python version and set of libraries. 使用virtualenv或pipenv创建“虚拟” Python安装-带有其自己的Python版本和一组库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM