python - RichIPythonWidget 导入对 pkgutil 模块的副作用

标签 python python-2.7 ipython

显然,导入RichIPythonWidget会对模块pkgutil产生影响。

测试环境:

IPython版本:2.1.0 python 版本:2.7 和 2.7.6

显示问题的代码:

import os
import pkgutil

print 'Before 1 ... '
pkgutil.find_loader('os') # call 1
print 'After call 1 ... '

from IPython.qt.console.rich_ipython_widget import RichIPythonWidget

print 'Before call 2 ... '
pkgutil.find_loader('os') # call 2
print 'After call 2 ... '

输出:

Before call 1 ... 
After call 1 ... 
Before call 2 ... 
Traceback (most recent call last):
  File "issue.py", line 11, in <module>
    pkgutil.find_loader('os') # call 2
  File "/u/bl/Dev/work/inkqt/opt.SuSE-11.4/lib64/python2.7/pkgutil.py", line 467, in find_loader
    loader = importer.find_module(fullname)
TypeError: find_module() takes exactly 3 arguments (2 given)

据我了解,我的问题似乎与添加到 sys.meta_path 的对象有关 由 IPython 使用,但由 pkgutil 模块使用错误的接口(interface)。 但我很难决定谁有罪......

任何解决方法将不胜感激。

谢谢

-贝努瓦

最佳答案

这很可能是由于 IPython 在 IPython/external/qt_loaders.py 中安装了 Qt ImportDenier。 find_module 方法不遵循 finder.find_module(fullname, path=None) 的 PEP302 签名,其中路径是可选的。

我在 IPython 上提交了一个问题:https://github.com/ipython/ipython/issues/5932 .

关于python - RichIPythonWidget 导入对 pkgutil 模块的副作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23960220/

相关文章:

html - 自定义ipython notebook的欢迎页面

Java 到 Python RSA

python - PyQt5 : start, 停止并暂停带有进度更新的线程

python - pandas 匹配两列并创建另一列

python - 如何在 Python 中配置日志记录

python - ipython笔记本中的Unicode

python - 求解具有四个变量的线性方程

django - 如何从时区获取UTC偏移值?

python - 重载按位运算符以在 Python 中使用 bool 值

python-3.x - Pyspark Column.isin() 用于大集合