简体   繁体   English

找不到命令:django-admin.py

[英]Command not found: django-admin.py

I am a complete beginner to Python/Django, but I want to dive right in and start experimenting.我是 Python/Django 的完全初学者,但我想直接潜入并开始试验。 Thus I was following this guide on installing Python/Django http://devcenter.heroku.com/articles/django .因此,我按照本指南安装 Python/Django http://devcenter.heroku.com/articles/django

Everything is working fine until the step一切正常,直到步骤

django-admin.py startproject hellodjango

Where I get我在哪里

command not found: django-admin.py

Now I have tried a few things, but none have really worked out.现在我尝试了一些东西,但没有一个真正奏效。 Is there someone kind enough to point me in the right direction?有没有好心的人给我指出正确的方向?

PS Is there a great guide out there on running Python/Django locally on a Mac to run and test apps? PS 是否有关于在 Mac 上本地运行 Python/Django 以运行和测试应用程序的出色指南?

I'm on Mac OS X Lion, Python 2.7.我在 Mac OS X Lion,Python 2.7 上。

当这对我不起作用时,我尝试了python -m django startproject mysite并且它起作用了。

Actually, if you use Ubuntu, it's just django-admin not django-admin.py .实际上,如果你使用 Ubuntu,它只是django-admin而不是django-admin.py

Resides in /usr/bin位于/usr/bin
Probably the same thing on Mac. Mac上可能是同样的事情。
You're using a Windows tutorial.您正在使用 Windows 教程。

It may also tell you它也可能告诉你

python manage.py runserver

and that is actually那实际上是

python ./manage.py runserver

I tried as the method, it worked.我试过这个方法,它奏效了。

pip uninstall django
sudo pip install django
django-admin startproject example

It worked well.它运作良好。

Make sure you properly did the source bin/activate command.确保您正确执行了source bin/activate命令。 If you skip that, or do it in a different terminal window, or close the window then re-open it, you won't be in the virtualenv and you won't have access to the django-admin.py command in your environment.如果您跳过它,或者在不同的终端窗口中执行它,或者关闭窗口然后重新打开它,您将不会在 virtualenv 中,并且您将无法访问环境中的django-admin.py命令.

如果你在 Windows 上,这对我有用(使用 pylauncher):

$ py -m django startproject myproject

To solve this problem, you need:要解决此问题,您需要:

  1. Find the main folder of Django, and find the django-admin.py file找到Django的主文件夹,找到django-admin.py文件

    Typically, the file is in <YOUR_DJANGO_FOLDER>/bin/django-admin.py通常,该文件位于<YOUR_DJANGO_FOLDER>/bin/django-admin.py

  2. Create a link for this file为这个文件创建一个链接

    ln -s /bin/django-admin.py /usr/local/bin/django-admin ln -s /bin/django-admin.py /usr/local/bin/django-admin

  3. Type django-admin in your command to check if it works在您的命令中输入django-admin以检查它是否有效

As Timmy said above, it could just be that django-admin.py is not on your system path.正如 Timmy 上面所说,可能只是 django-admin.py 不在您的系统路径上。 See here - https://code.djangoproject.com/wiki/InstallationPitfalls - for 3 possible causes with solutions.请参阅此处 - https://code.djangoproject.com/wiki/InstallationPitfalls - 了解解决方案的 3 个可能原因。

To Windows users致 Windows 用户

using django-admin instead of django-admin.py worked for me in Windows.使用django-admin而不是django-admin.py在 Windows 中为我工作。

在此处输入图像描述

For me this one worked对我来说,这个工作

python3 -m django startproject mysite

Then it doesn't tell you that it created file you must check by yourself in your home然后它不会告诉您它创建了您必须在家中自己检查的文件

hardrive/user/urhome
python3 -m django startproject mango

I have used follwong command to install (/usr/local/bin) MAC OS我使用 follwong 命令安装 (/usr/local/bin) MAC OS

pip install django

django-admin startproject mysite

The following guide in official site https://code.djangoproject.com/wiki/InstallationPitfalls官方网站https://code.djangoproject.com/wiki/InstallationPitfalls中的以下指南

First, you should find location of django-admin.py by首先,您应该通过以下方式找到django-admin.py的位置

which django-admin.py

Example: in my case示例:在我的情况下

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/bin/django-admin.py /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/bin/django-admin.py

You use sudo ln -s to relocate django-admin-py to /usr/local/bin您使用sudo ln -sdjango-admin-py重新定位到/usr/local/bin

sudo ln -s /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/bin/django-admin.py /usr/local/bin/django-admin.py

after that change permission of the django-admin to be executable sudo chmod +x /usr/local/bin/django-admin.py之后将 django-admin 的权限更改为可执行sudo chmod +x /usr/local/bin/django-admin.py

Now you can use django-admin.py startproject mysite to create your django project现在您可以使用django-admin.py startproject mysite来创建您的 django 项目


If you want to change django-admin.py to django-admin to look like more compact you can use sudo mv /usr/local/bin/django-admin.py /usr/local/bin/django-admin如果您想将django-admin.py更改为django-admin看起来更紧凑,您可以使用sudo mv /usr/local/bin/django-admin.py /usr/local/bin/django-admin

Hope this help for you !希望这对你有帮助!

我只是遇到了同样的问题,我刚刚进行了升级,就是这样,它起作用了,我希望这对 Linux 中的未来问题有用:

pip install --upgrade django

To windows users out there: I have faced this problem several times and here are the checkpoints:对于那里的 Windows 用户:我已经多次遇到这个问题,这里是检查点:

When there is problem initiating a new project, make sure:当启动新项目出现问题时,请确保:

1) python is working in the command line (type in python and see if you get the console) 1)python在命令行中工作(输入python,看看你是否得到了控制台)

2) specify the full path of django-admin.py in the command 2)在命令中指定django-admin.py的完整路径

3) check django-admin.py is in the system path 3)检查django-admin.py是否在系统路径中

4) cd the command line path to where you want the new project 4)cd命令行路径到你想要新项目的地方

Screenshot of what finally worked for me (only the last command): https://flic.kr/p/r9LJ67 (stackoverflow doesn't allow me to post pictures yet)最终对我有用的屏幕截图(仅最后一个命令): https ://flic.kr/p/r9LJ67(stackoverflow 不允许我发布图片)

If you come across command not found: django-admin.py problem which means you don't installed django frame work.如果你遇到command not found: django-admin.py问题,这意味着你没有安装 django 框架。 You should install the framework using pip.您应该使用 pip 安装框架。

pip install django

After that look at the directory if the related script exist or not.之后查看目录是否存在相关脚本。
Look into C:\Python27\Scripts folder to check for django-admin.py exist or not.查看C:\Python27\Scripts文件夹以检查 django-admin.py 是否存在。

if you install django by pip如果你通过 pip 安装 django

  • ensure you have installed django:确保您已安装 django:

pip list or pip freeze点子列表或点子冻结

if there is django then如果有 django 那么

  • get location of django:获取 django 的位置:

pip show django点子秀 django

if location is '/Users/xxxxx/Library/Python/2.7/lib/python/site-packages' then如果位置是 '/Users/xxxxx/Library/Python/2.7/lib/python/site-packages' 然后

  • relocate django-admin-py to /usr/local/bin:将 django-admin-py 重新定位到 /usr/local/bin:

ln -s /Users/xxxxx/Library/Python/2.7/lib/python/site-packages/django/bin/django-admin.py /usr/local/bin/django-admin.py ln -s /Users/xxxxx/Library/Python/2.7/lib/python/site-packages/django/bin/django-admin.py /usr/local/bin/django-admin.py

This simply worked for me.这对我有用。 Install django on your virtualenv:在你的 virtualenv 上安装 django:

pip install django

And then run:然后运行:

django-admin startproject myprojectname

Get site-package path with Python:使用 Python 获取站点包路径:

import site; site.getsitepackages()

And run django-admin.py directly:并直接运行 django-admin.py:

python (your-site-package-addresss)/django/bin/django-admin.py startproject hellodjango



On Mac: If this works you can go and add django-admin.py to your path using symlink:在 Mac 上:如果可行,您可以使用符号链接将 django-admin.py 添加到您的路径中:

sudo ln -s (your-site-package-addresss)/django/bin/django-admin.py /usr/local/bin/django-admin

(could be that you have to reopen terminal or reinstall django to get the symlink working) (可能是您必须重新打开终端或重新安装 django 才能使符号链接正常工作)

我将完整的python路径更改为桌面并尝试过,它对我来说效果很好

There may be a chance that your path is not correct.您的路径可能不正确。 Ubuntu has a .local/bin folder which pip uses to install module binaries and you need it in your path to use django or any shell commands installed using pip. Ubuntu 有一个 .local/bin 文件夹,pip 使用它来安装模块二进制文件,您需要在路径中使用它来使用 django 或使用 pip 安装的任何 shell 命令。

  • Open ~/.bashrc or ~/.zshrc打开~/.bashrc~/.zshrc
  • Add the following line and save it添加以下行并保存
export PATH="/home/animesh/.local/bin:$PATH"
  • restart the shell with source ~/.zshrc使用source ~/.zshrc重新启动 shell

RHEL股票 python 配置上:

django-admin.py startproject mysite

I'm running macOS and I'm using pyenv instead of virtualenv.我正在运行 macOS,我使用的是 pyenv 而不是 virtualenv。 I'm not sure if they behave similarly, but I was having the same problem in which django-admin.py was not found.我不确定它们的行为是否相似,但我遇到了同样的问题,即没有找到 django-admin.py。

After a while I've noticed that I had a warning after installing django: pyenv: cannot rehash: /Users/msvolenski/.pyenv/shims/.pyenv-shim exists过了一会儿,我注意到安装 django 后出现警告: pyenv: cannot rehash: /Users/msvolenski/.pyenv/shims/.pyenv-shim exists

Once I deleted this file and ran pyenv rehash it all started working perfectly.一旦我删除了这个文件并运行了pyenv rehash ,它就开始完美地工作了。

Hope this helps!希望这可以帮助!

For Windows Users first search for django-admin, right click on the file that has been found and open file location and keep it open.对于 Windows 用户,首先搜索 django-admin,右键单击找到的文件并打开文件位置并保持打开状态。

Using Windows Powershell, cd into the the folder where you want to create your django project使用 Windows Powershell,cd 进入您要创建 django 项目的文件夹

when your in the right folder write the full path of where django-admin is located in my case I am using Anaconda 3 so the file location is当你在正确的文件夹中写下 django-admin 所在位置的完整路径时,我使用的是 Anaconda 3,所以文件位置是

C:\Users\Sen\Anaconda3\Scripts C:\Users\Sen\Anaconda3\Scripts

so in Windows PowerShell type C:\Users\Sen\Anaconda3\Scripts\django-admin.py startproject [name of project]所以在 Windows PowerShell 中键入 C:\Users\Sen\Anaconda3\Scripts\django-admin.py startproject [项目名称]

hope this helps!希望这可以帮助!

我在迁移到 AWS Beanstalk 时遇到了同样的问题,它已安装并且所有内容都已安装,但我注意到别名不起作用但是当我调用整个事物路径并且一切正常时,我只是重新启动了这些盒子并且它起作用了我认为别名列表是安装后不会自动更新。

It has to do with the PATH:它与PATH有关:

Put this in the .bash_profiel and the source it (for mac users only): (change the location with the location of your installed python libraries)把它放在 .bash_profiel 和它的源代码中(仅适用于 mac 用户):(用你安装的 python 库的位置更改位置)

PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}"
export PATH

If someone is facing the same problem, and is on MacOs, here is what I did, and it worked for me:如果有人面临同样的问题,并且在 MacOs 上,这就是我所做的,它对我有用:

If you've installed python directly from the official website, uninstall it, and install it once again using brew:如果你直接从官网安装了python,卸载它,然后使用brew再次安装:

$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

$ brew install python3

This will also install the pip3 for you, so you don't have to install it by yourself.这也将为您安装 pip3,因此您不必自己安装。

I was facing the same issue.我面临着同样的问题。

The issue resolved after I upgraded the django version using在我使用升级 django 版本后问题解决了

pip install --upgrade django

Then run然后运行

django-admin startproject mysite

Hope this helps!希望这可以帮助!

There was a space in one of the names in the path to my project.我的项目路径中的一个名称中有一个空格。 I set up a new virtual environment in a new directory and did all the same things and it works.我在一个新目录中设置了一个新的虚拟环境并做了所有相同的事情并且它可以工作。

Sometimes it is the simple things...有时候是很简单的事情...

就我而言,我只是忘记运行pip install django

Since you're just starting out.因为你才刚刚开始。 It is very important to adopt best practices.采用最佳实践非常重要。 You will face many dependency related issues with this approach of development.使用这种开发方法,您将面临许多与依赖相关的问题。 In this case it is always recommended to work with a virtual environment for each python project.在这种情况下,始终建议为每个 python 项目使用虚拟环境。

This will ensure fresh installation of project-specific dependencies that do not overlap with what the system you are running on already has.这将确保全新安装特定于项目的依赖项,这些依赖项不会与您正在运行的系统重叠。

If you have not already noticed, you will come across more issues such as python3 not working with earlier versions of django.如果您还没有注意到,您会遇到更多问题,例如 python3 无法与早期版本的 django 一起使用。 pip will skip install as it checks and finds a version of django already installed. pip 将跳过安装,因为它会检查并找到已安装的 django 版本。 So this cannot be stressed enough, always use a virtual environment for local setups.因此,这怎么强调都不过分,请始终使用虚拟环境进行本地设置。

to do so:这样做:

  1. cd [your project path] cd [你的项目路径]

virtualenv venv virtualenv venv

  1. you can active your environment by :您可以通过以下方式激活您的环境:

source ./venv/bin/active来源 ./venv/bin/active

  1. install your requirements packages with pip :使用 pip 安装您的需求包:

pip install -r or pip install you can also install your requirements modules without activate the environment pip install -r 或 pip install 你也可以在不激活环境的情况下安装你的需求模块

./venv/bin/pip install ./venv/bin/pip 安装

  1. to run your python script use :运行你的 python 脚本使用:

python <.py file> python <.py 文件>

and if you didn't activate your env use :如果你没有激活你的环境使用:

./venv/bin/python <.py file> ./venv/bin/python <.py 文件>

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

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