gpt4 book ai didi

macos - OS X - 谁能解释为什么我在安装 ipython3 后在我的 .pythonrc.py 文件中收到操作系统错误,或者给我一个比这更强大的解决方案?

转载 作者:行者123 更新时间:2023-12-04 02:20:59 26 4
gpt4 key购买 nike

我使用 pip3 安装了 ipython3。

pip3 install ipython[all]

当我运行 python 时,它遇到了来 self 的 ~/.pythonrc.py 文件的错误(仅在 Python 3 而不是 Python 2)。

Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 23 2015, 02:52:03)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Traceback (most recent call last):
File "/Users/Mike/.pythonrc.py", line 43, in <module>
readline.read_history_file(history_path)
OSError: [Errno 22] Invalid argument

我在 stackoverflow 上找不到答案,但进行了一些挖掘并找到了解决方案。我不确定为什么这现在有效,或者是否有更好的解决方案。

在 .pythonrc.py 文件中:

try:
import readline
except ImportError:
pass

history_path = os.path.expanduser('~/.pyhistory')
if os.path.isfile(history_path):
readline.read_history_file(history_path)
atexit.register(lambda x=history_path: readline.write_history_file(x))

解决方案是改为导入 gnureadline:

try:
import gnureadline as readline
except ImportError:
pass

谁能告诉我是否有更可靠的解决方案或者为什么会发生这种情况?

最佳答案

我刚找到答案:

import gnureadline as readline

基于链接:

gnureadline for IPython OSX

On OSX, if you are using the built-in Python shipped by Apple, you will be missing a proper readline implementation as Apple ships instead a library called libedit that provides only some of readline’s functionality. While you may find libedit sufficient, we have occasional reports of bugs with it and several developers who use OS X as their main environment consider libedit unacceptable for productive, regular use with IPython.

Therefore, IPython on OS X depends on the gnureadline module. We will not consider completion/history problems to be bugs for IPython if you are using libedit.

关于macos - OS X - 谁能解释为什么我在安装 ipython3 后在我的 .pythonrc.py 文件中收到操作系统错误,或者给我一个比这更强大的解决方案?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29572484/

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