"ValueError: _type_ 'v' not supported" error after installing PyReadline

"ValueError: _type_ 'v' not supported" error after installing PyReadline

我安装 PyReadline 后,IPython 将无法使用。当我卸载它时,它又开始工作了。

ipython 的堆栈跟踪:

(py2.7_monitor)[root@vm10-136-8-98 monitor]# ipython
WARNING: IPython History requires SQLite, your history will not be saved
Traceback (most recent call last):
  File "/home/py2.7_monitor/bin/ipython", line 11, in <module>
    sys.exit(start_ipython())
  File "/home/py2.7_monitor/lib/python2.7/site-packages/IPython/__init__.py", line 118, in start_ipython
    return launch_new_instance(argv=argv, **kwargs)
  File "/home/py2.7_monitor/lib/python2.7/site-packages/traitlets/config/application.py", line 591, in launch_instance
    app.initialize(argv)
  File "<string>", line 2, in initialize
  File "/home/py2.7_monitor/lib/python2.7/site-packages/traitlets/config/application.py", line 75, in catch_config_error
    return method(app, *args, **kwargs)
  File "/home/py2.7_monitor/lib/python2.7/site-packages/IPython/terminal/ipapp.py", line 314, in initialize
    self.init_shell()
  File "/home/py2.7_monitor/lib/python2.7/site-packages/IPython/terminal/ipapp.py", line 330, in init_shell
    ipython_dir=self.ipython_dir, user_ns=self.user_ns)
  File "/home/py2.7_monitor/lib/python2.7/site-packages/traitlets/config/configurable.py", line 380, in instance
    inst = cls(*args, **kwargs)
  File "/home/py2.7_monitor/lib/python2.7/site-packages/IPython/core/interactiveshell.py", line 531, in __init__
    self.init_readline()
  File "/home/py2.7_monitor/lib/python2.7/site-packages/IPython/core/interactiveshell.py", line 1941, in init_readline
    import IPython.utils.rlineimpl as readline
  File "/home/py2.7_monitor/lib/python2.7/site-packages/IPython/utils/rlineimpl.py", line 21, in <module>
    _rl = __import__(_rlmod_name)
  File "/home/py2.7_monitor/lib/python2.7/site-packages/readline.py", line 6, in <module>
    from pyreadline.rlmain import Readline
  File "/home/py2.7_monitor/lib/python2.7/site-packages/pyreadline/__init__.py", line 12, in <module>
    from . import logger, clipboard, lineeditor, modes, console
  File "/home/py2.7_monitor/lib/python2.7/site-packages/pyreadline/clipboard/__init__.py", line 13, in <module>
    from .win32_clipboard import GetClipboardText, SetClipboardText
  File "/home/py2.7_monitor/lib/python2.7/site-packages/pyreadline/clipboard/win32_clipboard.py", line 37, in <module>
    import ctypes.wintypes as wintypes
  File "/usr/local/lib/python2.7/ctypes/wintypes.py", line 23, in <module>
    class VARIANT_BOOL(_SimpleCData):
ValueError: _type_ 'v' not supported

As stated 在他们的网站上,PyReadline 库用于 Windows.

查看堆栈跟踪的最后几行:

import ctypes.wintypes as wintypes
File "/usr/local/lib/python2.7/ctypes/wintypes.py", line 23, in <module>
class VARIANT_BOOL(_SimpleCData):
ValueError: _type_ 'v' not supported

它正在尝试从 ctypes 导入 windows 特定数据类型,这显然是不可能的,因为您不是 运行 Windows.

这可能对 2020 年或以后的任何人都没有帮助,但我还是想在这里记录下来以供后代使用。

我在 HPC 集群环境中安装 Python 2.7.16 时遇到了相同的 ValueError: _type_ 'v' not supported 回溯,试图从 2012 年开始安装 pdbpp, which depends on fancycompleter, which depends on pyreadline, which imports ctypes.wintypes and is affected by this this core Python issue

ctypes.wintypes 确实不应在 non-Windows 平台上导入(Cygwin、MSYS2 和 Git Bash 在技术上是 non-Windows,因为他们将拥有 真正的 GNU Readline 库,不需要纯 Python 垫片)。

但是,如果它 在 non-Windows 平台上导入的,由于上述问题,ctypes.wintypes 抛出 ValueError 而不是一个 ImportError,这意味着期望捕获 ImportError 的典型 try/except 会因为未处理的异常而崩溃。

Pdbpp 的 fancycompleter,或者更确切地说是 pyreadline,不知何故成了这个的牺牲品。我对谁应该受到指责感到困惑,因为 fancycompleter 的 setup.py 不应该将 pyreadline 作为依赖引入 except on Windows,但不知何故 在我的 Linux系统。 如果它在那里,fancycompleter 会尝试导入它。

我能想到的是,我的 pip 缓存中可能有一个旧的 fancycompleter,它的 setup.py 中有一个拼写错误,它在不应该的时候引入了 pyreadline,因为它 一次又一次地抓住了这种依赖性。

实际上最终为我解决了这种情况的是 pip uninstall pyreadline,然后 pip install -U --ignore-installed --no-cache-dir fancycompleter 得到一个“新鲜”版本的 fancycompleter,它没有引入不必要的 pyreadline 依赖。