简体   繁体   English

为什么我不能运行 django-admin?

[英]Why can't I run django-admin?

So I always have problems installing things.所以我总是在安装东西时遇到问题。 Programming is never a problem, but installing always is.编程从来都不是问题,但安装总是如此。 Mainly because I do things the way they are supposed to do according to the official websites but it doesn't work.主要是因为我按照官方网站应该按照他们应该做的方式做事,但它不起作用。 It's like a cooking recipe, except you can't just improvise if you don't know what "salt" or "sugar" is.这就像一个烹饪食谱,但如果你不知道“盐”或“糖”是什么,就不能即兴发挥。 (If anyone got advice on that as a general problem, please tell me!) (如果有人对此作为一般问题提出建议,请告诉我!)

Today I tried getting into the django web framework.今天我尝试进入 django web 框架。 I installed and verified the installation as is supposed .按预期安装并验证了安装。 When I wanted to start the tutorial , the second thing I was asked to do (after verifying the Version) was to cd into the directory I wanted the code to run in (which I did) and then run:当我想开始教程时,我被要求做的第二件事(在验证版本之后)是 cd 进入我希望代码运行的目录(我这样做了),然后运行:

django-admin startproject mysite django-admin startproject mysite

When I did that, this appeared:当我这样做时,出现了:

Command 'django-admin' not found, but can be installed with:找不到命令“django-admin”,但可以安装:

sudo apt install python3-django sudo apt install python3-django

Alright.好吧。 Fine I thought.很好,我想。 That's what they put this in the tutorial in the next line:这就是他们在下一行的教程中提出的内容:

If it didn't work, see Problems running django-admin .如果它不起作用,请参阅运行 django-admin 的问题

So I click that link.所以我点击那个链接。 Now it says this:现在它说:

command not found: django-admin¶找不到命令:django-admin¶

django-admin should be on your system path if you installed Django via pip.如果您通过 pip 安装了 Django,则 django-admin 应该在您的系统路径上。 If it's not on your path, you can find it in site-packages/django/bin, where site-packages is a directory within your Python installation.如果它不在您的路径中,您可以在 site-packages/django/bin 中找到它,其中 site-packages 是 Python 安装中的一个目录。 Consider symlinking to django-admin from some place on your path, such as /usr/local/bin.考虑从路径上的某个位置(例如 /usr/local/bin)符号链接到 django-admin。

I have no idea what any of that means, so I am kinda stuck now:我不知道这意味着什么,所以我现在有点卡住了:

django-admin should be on your system path if you installed Django via pip.如果您通过 pip 安装了 Django,则 django-admin 应该在您的系统路径上。

I don't know what a system path is.我不知道系统路径是什么。

If it's not on your path,如果它不在你的道路上,

How do I know that?我怎么知道?

you can find it in site-packages/django/bin你可以在 site-packages/django/bin 中找到它

Ok, but what is "it" and what do I do with "it" when I found it?好的,但是什么是“它”,当我找到它时,我该怎么处理它?

where site-packages is a directory within your Python installation.其中 site-packages 是 Python 安装中的目录。

What is "site-packages"?什么是“站点包”?

Consider symlinking to django-admin考虑符号链接到 django-admin

I have no idea what that means, but what is meant by "consider"?我不知道那是什么意思,但“考虑”是什么意思? That seems to be the only solution provided, so I don't really have a choice, right?这似乎是提供的唯一解决方案,所以我真的别无选择,对吧? And if I do, what is it?如果我这样做了,那是什么?

from some place on your path, such as /usr/local/bin.从路径上的某个位置,例如 /usr/local/bin。

I don't know what that means.我不知道那是什么意思。

Maybe I am just lazy person and should sit here for days and google every single term and concept and explanation.也许我只是一个懒惰的人,应该在这里坐几天,用谷歌搜索每一个术语、概念和解释。 I'm ready to be flamed for this.我已经准备好为此而发火了。 But I am kind of sick of tutorials acting like every user has been programming for the past 50 years and knows every single concept of Linux, all its terms and sub-terms by heart.但是我有点厌倦了教程,就像每个用户在过去 50 年中一直在编程,并且知道 Linux 的每一个概念,它的所有术语和子术语都牢记在心。 Where am I supposed to start when everything relies on something else I don't know about?当一切都依赖于我不知道的其他东西时,我应该从哪里开始? I just feel like a toddler whenever I learn something new here and then I just go back to what I already know or it takes ages.每当我在这里学到新东西时,我都会觉得自己像个蹒跚学步的孩子,然后我只是 go 回到我已经知道的或者需要很长时间。 I don't even know if django is good.我什至不知道 django 好不好。 In the end it might be horrible and I just waste a lot of time.最后可能会很糟糕,我只是浪费了很多时间。 Sorry for ranting a little, but it's really annoying to not be able to grasp anything without reading rfc standards for hours before you learn anything new.抱歉有点咆哮,但是在你学习任何新东西之前几个小时不阅读 rfc 标准就无法掌握任何东西真的很烦人。 Whoever is replying to this, thank you!哪位大神回复一下,谢谢!

Edit: Minor formatting changes.编辑:较小的格式更改。

Do I understand that you're on a Linux setup, eg Ubuntu?我是否了解您正在使用 Linux 设置,例如 Ubuntu? If not, it might be worthwhile to specify what kind of OS you are using.如果没有,那么指定您使用的操作系统类型可能是值得的。 You can try a few things:你可以尝试几件事:

  1. In bash, run python --version to find which version of Python it is you're using (I didn't see this in your description of the issue).在 bash 中,运行python --version以查找您正在使用的 Python 版本(我在您对问题的描述中没有看到这一点)。

  2. Open up a python shell ( python from bash).打开 python shell (来自 bash 的python )。 When inside the python shell, try this: >>> import django .在 python shell 内部时,试试这个: >>> import django Does that produce an error, or is there no output?这会产生错误,还是没有 output? If you get an error (eg 'ImportError'), please describe briefly what it says.如果您遇到错误(例如“ImportError”),请简要描述它所说的内容。

  3. If you did not get an error at step 2, you might try >>> from django.views.generic import FormView .如果您在第 2 步没有收到错误,您可以尝试>>> from django.views.generic import FormView Does this also seem to do nothing?这似乎也无济于事吗? If 'nothing happens', what do you get if you try >>> FormView.as_view() ?如果“什么都没发生”,如果您尝试>>> FormView.as_view()会得到什么? (it should produce something like <function FormView at 0x101b613a0> (它应该产生类似<function FormView at 0x101b613a0>

  4. If you did get an error at step 2, could you look at what output you got when running python -m pip install Django ?如果您在步骤 2 中确实遇到了错误,您能否看看运行python -m pip install Django Was there any warning there, like something telling you that the package was installed to a folder/path that you don't have access to?那里是否有任何警告,例如告诉您 package 已安装到您无权访问的文件夹/路径?

I had the same problem and I did not know why because the first time I followed the tutorial steps and it worked well.我遇到了同样的问题,我不知道为什么,因为我第一次按照教程步骤操作,效果很好。 I found a solution but using a venv and I didn't wanna do it.我找到了解决方案,但使用了venv ,但我不想这样做。 So I kept searching and finally I only had to do two things, first I started django-admin but using a terminal as a administrator (I am using windows) and there was no errors, it created the folders properly.所以我一直在寻找,最后我只需要做两件事,首先我启动django-admin但使用终端作为管理员(我使用的是 windows)并且没有错误,它正确创建了文件夹。 Later when I tried to run the app using后来当我尝试使用

python manage.py runserver it threw and error python manage.py runserver它抛出并出错

from django.core.management import execute_from_command_line ModuleNotFoundError: No module named 'django'从 django.core.management import execute_from_command_line ModuleNotFoundError: No module named 'django'

So I only removed the comment on the first line and the error disappeared, right now I am running the default view without any problems.所以我只删除了第一行的注释,错误就消失了,现在我运行默认视图没有任何问题。

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

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