简体   繁体   English

运行 django-admin 后出现“bash:django-admin:找不到命令”

[英]“bash: django-admin: command not found” after running django-admin

I had similar problems with pip that was fixed with "python3 -m" but now after install Django I want to make a new project.我在使用“python3 -m”修复的 pip 上遇到了类似的问题,但现在在安装 Django 后我想创建一个新项目。

When I try to run "django-admin startproject..." I get "bash: django-admin: command not found".当我尝试运行“django-admin startproject ...”时,我得到“bash: django-admin: command not found”。

I don't know if I should mention it but, this is in a virtualenv.我不知道我是否应该提及它,但是,这是在 virtualenv 中。

python3 -m pip freeze: Django==3.0.6 python3 -m pip 冻结:Django==3.0.6

echo $PATH: /home/alatimer/Environments/DjangoTutoria_env/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin echo $PATH:/home/alatimer/Environments/DjangoTutoria_env/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games: /usr/local/games:/snap/bin

My problem was i was using python version 2.7 in the venv instead of version 3.6.9.我的问题是我在 venv 中使用 python 2.7 版而不是 3.6.9 版。

I assume the older python couldn't recognize the commands (this even includes pip commands).我假设较旧的 python 无法识别命令(这甚至包括 pip 命令)。

Your problem is that your shell doesn't know where that program is, and the places it searches doesn't have it.您的问题是您的 shell 不知道该程序在哪里,并且它搜索的地方没有它。

Notably, the shell would look for a program specifically if the name were qualified some way, where you name a location at the start.值得注意的是,shell 会在名称以某种方式限定的情况下专门寻找程序,您在开始时命名一个位置。 So, you could use "/long/path/to/django-admin" or "./django-admin" (if it's in the "." current directory).因此,您可以使用“/long/path/to/django-admin”或“./django-admin”(如果它在“.”当前目录中)。

Always qualify names that aren't standard programs.始终限定非标准程序的名称。 It isn't safe to mutate PATH to include a path relative to your current directory .改变 PATH 以包含相对于当前目录的路径是不安全的. . . Instead, name your personal programs with location when you run them, ./program .相反,在运行它们时使用位置命名您的个人程序, ./program

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

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