Python中調用help()報錯:Not enough Memory

系統環境:win7 SP1 Python3.6
最近在ipython中調用help()函數,提示:Not enough Memory

[In1]: help(help)
Not enough Memory

記得以前使用時沒有問題的,然後再網上查了一下,
http://bugs.python.org/issue19914

For posterity for anyone that finds this old issue, I investigated this problem in the debugger in Windows 7. It turns out that more.com (the pager used by Python’s help) calls MultiByteToWideChar [1] with dwFlags passed as MB_PRECOMPOSED (1), which is forbidden for UTF-8. The error message is just a generic error that incorrectly assumes decoding the byte string failed due to running out of memory.

msg261838 Author: Eryk Sun (eryksun) Date: 2016-03-16 04:28

注意看這條記錄,裏面提到了這個是window7上的一個bug:使用UTF-8時,就會引起這個錯誤
win10上已經解決了

解決辦法如下,更改代碼頁爲850

# 命令行裏輸入一下命令,更改代碼頁爲 850 多語種 (MS-DOS Latin1) 
C:\> chcp 850
C:\> python
...
>>> help(help)
>class _Helper(builtins.object)
 |  Define the builtin 'help'.
...
C:\> ipython
...
[In1]: help(help)
>class _Helper(builtins.object)
 |  Define the builtin 'help'.
...

總結:對系統底層不是很懂,所以引用的部分只選擇了描述部分,有興趣的可以直接觀看原文。

發佈了35 篇原創文章 · 獲贊 7 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章