gpt4 book ai didi

python - 如何在 Windows 版 Git Bash 中启用 Python 上次命令历史记录?

转载 作者:太空宇宙 更新时间:2023-11-03 15:34:29 24 4
gpt4 key购买 nike

在 Python 解释器中输入和执行的最后一个 Python 命令可以通过按向上箭头来调用。

这在 Windows CMD 和 Powershell 中按预期工作,但在 Git Bash for Windows 中向上箭头无效

或者,如果我尝试 CTRL + P 我得到:

user@DESKTOP MINGW64 ~
$ python
Python 3.7.1 (default, Dec 10 2018, 22:54:23) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> a = 1
>>> ^P^P

同样,Alt + P 如另一个答案中所建议的那样,只会在命令输入上产生一个 p

我们如何为 Git Bash 启用 Python 命令历史记录?

最佳答案

在您的 .pythonstartup 文件中添加此行,如果不存在则创建它:

import readline

请务必将 .pythonstartup 文件的完整路径添加为名为 PYTHONSTARTUP 的环境变量

这应该可以解决问题。如果出现导入​​错误,请像这样安装它:

pip install pyreadline

或者,如果您使用的是 Anaconda,请使用:

conda install pyreadline

关于python - 如何在 Windows 版 Git Bash 中启用 Python 上次命令历史记录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55679574/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com