python - 如何在 Windows 版 Git Bash 中启用 Python 上次命令历史记录?
问题描述
在 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+只会在命令输入上产生 a 。Pp
我们如何为 Git Bash 启用 Python 命令历史记录?
解决方案
在您的.pythonstartup
文件中添加此行,如果不存在则创建它:
import readline
请务必将.pythonstartup
文件的完整路径添加为名为的环境变量PYTHONSTARTUP
那应该解决它。如果遇到导入错误,请按如下方式安装:
pip install pyreadline
或者,如果您使用的是 Anaconda,请使用:
conda install pyreadline
推荐阅读
- json - 将数据输出到 JSON 文件 csharp (unity)
- c# - 在从页面创建 iTextSharp.text.pdf.PdfDictionary 之前如何检查 PDF 是否有标题
- python - 如何合并熊猫列和合并日期时间
- ffmpeg - FFmpeg 不通过 Discord.py BOT 播放任何音频
- c# - C# 从重定向的 StandardOutput 异步读取数据
- php - laravel 中简单 HTML DOM 解析器的问题
- r - xts 时间序列的 rbind 错误是错误还是功能
- java - 如何在 Kotlin 中实例化接口?
- wordpress - 在woocommerce表单内的下拉列表中显示所有产品
- ios - “无法检索产品信息”“无效的产品标识符”SwiftyStoreKit iOS Swift Xcode