【问题标题】:Django -- manage.py shell doesn't work with git bash terminalDjango -- manage.py shell 不适用于 git bash 终端
【发布时间】:2016-08-13 11:19:34
【问题描述】:

所以我一直在关注this django 教程,并且在使用 git bash 终端时遇到了 manage.py 命令的一些问题。我在 Windows 10 上使用 Python 2.7.11 (Anaconda 2.4.1)、Django 1.9.5 和 git 2.8.1.windows.1。

特别是python manage.py runserver 和python manage.py shell 命令在使用 git bash 终端时似乎无法正常工作,但在使用 Anaconda 终端时它们可以正常工作。我想找到一种方法让它与 git bash 一起工作。

根据教程,我应该在运行python manage.py runserver时在终端上看到这个输出:

Performing system checks...

System check identified no issues (0 silenced).

April 19, 2016 - 15:50:53
Django version 1.9, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

使用 git bash,我知道有些东西正在工作,因为我可以在浏览器中导航到 http://127.0.0.1:8000/。我只是在终端上看不到任何输出。

我继续学习本教程,因为这并没有真正影响任何事情。它似乎工作,只是没有终端输出。然后我到了教程的this 部分,在这里你用python manage.py shell 打开一个shell。

使用 git bash,什么也没有发生。 shell 提示永远不会打开,就好像它被卡住了一样。没有错误,只是在没有命令提示符的情况下在新行上闪烁光标。如果我使用 Anaconda 终端做同样的事情,shell 会正常打开。

起初我以为是安装错误。所以,我尝试使用pip install 和conda install 安装django,但我仍然遇到同样的问题。我不太确定这里发生了什么,而且我还没有设法找到解决方案。

非常感谢任何帮助。

更新:

我发现了一个similar question 并没有完全解决方案,但它建议使用pystuck 进行调试。我读了pystuckdocs,但不太明白如何使用它来解决这个问题。

【问题讨论】:

  • 我刚刚找到了可能被视为duplicate question 的内容。我花了很多时间寻找已经被问过的类似问题,但直到我决定发布这个问题之后才看到这个。我正在检查这个其他问题是否解决了我看到的问题。很快就会更新。
  • 有一个 SO git-bash 标签,可能有助于找到答案。
  • @C14L -- 谢谢。更新了标签。

标签: python django shell anaconda git-bash


【解决方案1】:

我也有这个问题,运行python manage.py runserver 时缺少详细输出,只存在高级页面响应。我使用的是 powershell 或 Git Cmd,这是一个选项...此修复还解决了使用 Git Bash 到 python manage.py makemigrations 和 python manage.py migrate 的问题,

选项:使用 Git Cmd 或 powershell。

临时修复:在 Git Bash 中运行此命令以生成此工作会话的详细输出:alias python='winpty python.exe'

Perm Fix: 在 .bashrc 文件中使用临时修复,git bash 将始终有详细的输出。

 cd ~      #Takes you to your root directory.
 touch .bashrc

使用 VIM 或您选择的编辑器编辑文件,添加以下行(注意:MS Windows 的记事本无法正确保存此文件。请勿使用记事本。):

 alias python='winpty python.exe'

重启 Git Bash。

注意: 在某些情况下,你会在启动 git bash 时得到一个提示:

"警告:找到 ~/.bashrc 但没有 ~/.bash_profile、~/.bash_login 或 〜/ .profile。

这看起来像是一个不正确的设置。一个 ~/.bash_profile , 将为您创建加载 ~/.bashrc。”

您会注意到为您创建了第二个文件 .bash_profile,您可以开始了!

就是这样……享受吧。

【讨论】:

    【解决方案2】:

    我不知道为什么,但我找到了一些解决方法。在 Windows 7(使用 Anaconda2)的 Git Bash 窗口中运行 python manage.py runserver 时,我也没有得到预期的结果:

    Performing system checks...
    System check identified no issues (0 silenced).
    
    February 09, 2017 - 17:39:48
    Django version 1.10.5, using settings 'mysite.settings'
    Starting development server at http://127.0.0.1:8090/
    Quit the server with CTRL-BREAK.
    

    在本机 Windows CMD 提示符下执行相同操作!!!!

    我在 Sublime Text 中打开了 manage.py,当我保存它(或项目中的任何其他文件)时,服务器(已启动并当前冻结在 git bash 窗口中)按预期启动。

    也许这对你有用。不知道为什么这样做或应该这样做...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-10-03
      • 1970-01-01
      • 1970-01-01
      • 2021-09-02
      • 2020-04-22
      • 2015-09-10
      • 2016-09-15
      相关资源
      最近更新 更多