【问题标题】:python manage.py runserver, shell, dbshell freezes on git-bashpython manage.py runserver、shell、dbshel​​l 在 git-bash 上冻结
【发布时间】:2015-09-10 19:17:35
【问题描述】:

我正在尝试在 git-bash 上的 windows 中的 python virtualenv 中运行交互式 shell,但它没有运行。奇怪的是,它似乎什么也没做,只是光标在下一行闪烁,没有输出。

$ python manage.py shell
|

但是,我可以运行诸如 migrate、makemigrations、sqlmigrate 之类的命令。命令出现问题 - shell、dbshel​​l、runserver。

这似乎是一些与 git-bash 相关的问题,因为我可以从命令行运行 shell。我在 Windows 上使用PortableGit-2.4.3.1-2nd-release-candidate-64-bit.7z.exe

【问题讨论】:

  • 你试过了吗? python manage.py shell_plus --ipython
  • @dabad 没有名为 IPython 的模块。顺便说一句,我没有使用 IPython。
  • 我想只是python manage.py shell_plus 不行吧?
  • @dabad 不。那没有。但它显示了一些关于弃用的输出。
  • 如果我遇到挂起程序的问题,我通常会在它们上尝试PyStuck...你能从中得到任何堆栈输出来显示发生了什么吗?

标签: python django windows git-bash


【解决方案1】:

问题是 python.exe 本身与 gitbash 有问题。据说和ncurses库有关。

解决方案是键入“winpty python.exe”而不是 python。 “winpty python.exe manage.py shell”应该可以工作。您还可以创建一个别名来绕过该问题。键入“alias python='winpty python.exe'”将使其“python manage.py shell”正常工作。

这个答案更好地解释了它: Python not working in the command line of git bash

【讨论】:

    【解决方案2】:

    在cmets中总结调查...

    调查这类问题的一个好方法是使用pystuck

    在这种情况下,它似乎是对 IPython 的某种内部依赖,因为安装 pystuck 也会安装 IPython,并且安装了 Both 后该错误不再重现。

    【讨论】:

    • 好吧,我现在会接受这个答案,因为它至少让我继续我的工作.. 仍然需要看看为什么它不能与内置的 python 解释器一起工作。当我有时间时会和 pystuck 一起玩。同时,感谢您的回答:)
    • @Rohit Jain:是的——我也不太满意,所以我快速浏览了code。看起来 IPython 将优先使用 bpython,然后最终使用代码模块。我的猜测是你有一个狡猾的 bpython 安装。
    【解决方案3】:

    我不知道命令shelldbshell,但是对于runservercommand,我有同样的问题。我解决了跑步

    python manage.py runserver --noreload
    

    转到http://127.0.0.1:8000/ 并刷新浏览器。您的终端必须显示您网站的信息

    【讨论】:

      猜你喜欢
      • 2020-04-21
      • 1970-01-01
      • 2014-08-14
      • 2011-09-16
      • 1970-01-01
      • 1970-01-01
      • 2018-01-23
      • 2017-08-18
      相关资源
      最近更新 更多