加载 ipython qtconsole 时出错

Posted

技术标签:

【中文标题】加载 ipython qtconsole 时出错【英文标题】:Error loading ipython qtconsole 【发布时间】:2014-11-03 07:53:34 【问题描述】:

我在这里需要一些建议。我已经安装了 ipython (sudo pip install ipython[all])

我有 python 2.7,mac osx 10.9 64bits。

我正在尝试午餐 qtconsole

camilo-mbp:mvc cami$ ipython qtconsole
Traceback (most recent call last):
File "/usr/local/bin/ipython", line 8, in <module>
load_entry_point('ipython==2.2.0', 'console_scripts', 'ipython')()
File "/Library/Python/2.7/site-packages/IPython/__init__.py", line 120, in start_ipython
return launch_new_instance(argv=argv, **kwargs)
File "/Library/Python/2.7/site-packages/IPython/config/application.py", line 563, in   launch_instance
app.initialize(argv)
File "<string>", line 2, in initialize
File "/Library/Python/2.7/site-packages/IPython/config/application.py", line 92, in  catch_config_error
return method(app, *args, **kwargs)
File "/Library/Python/2.7/site-packages/IPython/terminal/ipapp.py", line 321, in initialize
super(TerminalIPythonApp, self).initialize(argv)
File "<string>", line 2, in initialize
File "/Library/Python/2.7/site-packages/IPython/config/application.py", line 92, in  catch_config_error
return method(app, *args, **kwargs)
File "/Library/Python/2.7/site-packages/IPython/core/application.py", line 381, in initialize
self.parse_command_line(argv)
File "/Library/Python/2.7/site-packages/IPython/terminal/ipapp.py", line 316, in   parse_command_line
return super(TerminalIPythonApp, self).parse_command_line(argv)
File "<string>", line 2, in parse_command_line
File "/Library/Python/2.7/site-packages/IPython/config/application.py", line 92, in   catch_config_error
return method(app, *args, **kwargs)
File "/Library/Python/2.7/site-packages/IPython/config/application.py", line 475, in   parse_command_line
return self.initialize_subcommand(subc, subargv)
File "<string>", line 2, in initialize_subcommand
File "/Library/Python/2.7/site-packages/IPython/config/application.py", line 92, in  catch_config_error
return method(app, *args, **kwargs)
File "/Library/Python/2.7/site-packages/IPython/config/application.py", line 406, in  initialize_subcommand
subapp = import_item(subapp)
File "/Library/Python/2.7/site-packages/IPython/utils/importstring.py", line 42, in import_item
module = __import__(package, fromlist=[obj])
File "/Library/Python/2.7/site-packages/IPython/qt/console/qtconsoleapp.py", line 58, in <module>
from IPython.external.qt import QtCore, QtGui
File "/Library/Python/2.7/site-packages/IPython/external/qt.py", line 23, in <module>
QtCore, QtGui, QtSvg, QT_API = load_qt(api_opts)
File "/Library/Python/2.7/site-packages/IPython/external/qt_loaders.py", line 258, in load_qt
api_options))
ImportError: 
Could not load requested Qt binding. Please ensure that
PyQt4 >= 4.7 or PySide >= 1.0.3 is available,
and only one is imported per session.

Currently-imported Qt library:   None
PyQt4 installed:                 False
PySide >= 1.0.3 installed:       False
Tried to load:                   ['pyside']

我已执行以下命令将安装的 pyQt4 设置为 True 并且工作正常

export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH

现在,我想安装 pyside,但出现了一些错误:

camilo-mbp:mvc cami$ pip install pyside
Downloading/unpacking pyside
Downloading PySide-1.2.2.tar.gz (9.3MB): 9.3MB downloaded
Running setup.py egg_info for package pyside
Removing  /private/var/folders/y3/xwgxtgzs27z5mwzhpmw244d00000gp/T/pip_build_cami/pyside/pyside_package

package init file 'pyside_package/PySide/__init__.py' not found (or not a regular file)
package init file 'pyside_package/pysideuic/__init__.py' not found (or not a regular file)
warning: no previously-included files matching '**' found under directory 'sources/pyside-examples/examples/hyperui'
warning: no previously-included files matching '**' found under directory 'sources/pyside-examples/mobility'
warning: no previously-included files matching '**' found under directory 'sources/shiboken/.git'
warning: no previously-included files matching '**' found under directory 'sources/pyside/.git'
warning: no previously-included files matching '**' found under directory 'sources/pyside-tools/.git'
warning: no previously-included files matching '**' found under directory 'sources/pyside-examples/.git'
warning: no files found matching '**' under directory 'pyside_package/PySide'
warning: no files found matching '**' under directory 'pyside_package/PySide/docs'
warning: no files found matching '**' under directory 'pyside_package/PySide/plugins'
warning: no files found matching '**' under directory 'pyside_package/PySide/imports'
warning: no files found matching '**' under directory 'pyside_package/PySide/translations'
warning: no files found matching '**' under directory 'pyside_package/PySide/include'
warning: no files found matching '**' under directory 'pyside_package/PySide/typesystems'
warning: no files found matching '**' under directory 'pyside_package/PySide/examples'
warning: no files found matching '**' under directory 'pyside_package/pysideuic'
warning: no files found matching '**' under directory 'pyside_package/pysideuic/Compiler'
warning: no files found matching '**' under directory 'pyside_package/pysideuic/port_v2'
warning: no files found matching '**' under directory 'pyside_package/pysideuic/port_v3'
warning: no files found matching '**' under directory 'pyside_package/pysideuic/widget-plugins'
Installing collected packages: pyside
Running setup.py install for pyside
Removing /private/var/folders/y3/xwgxtgzs27z5mwzhpmw244d00000gp/T/pip_build_cami/pyside/pyside_package
Python architecture is 64bit
error: Failed to find cmake. Please specify the path to cmake with --cmake parameter.
Complete output from command    /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python -c "import setuptools;__file__='/private/var/folders/y3/xwgxtgzs27z5mwzhpmw244d00000gp/T/pip_build_cami/pyside/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/y3/xwgxtgzs27z5mwzhpmw244d00000gp/T/pip-AjpsAb-record/install-record.txt --single-version-externally-managed:
Removing /private/var/folders/y3/xwgxtgzs27z5mwzhpmw244d00000gp/T/pip_build_cami/pyside/pyside_package

running install

running build

Python architecture is 64bit

error: Failed to find cmake. Please specify the path to cmake with --cmake parameter.

----------------------------------------
Cleaning up...
Command       /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python -  c "import   setuptools;__file__='/private/var/folders/y3/xwgxtgzs27z5mwzhpmw244d00000gp/T/pip_build_cami/pyside/s     etup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --  record /var/folders/y3/xwgxtgzs27z5mwzhpmw244d00000gp/T/pip-AjpsAb-record/install-record.txt --  single-version-externally-managed failed with error code 1 in   /private/var/folders/y3/xwgxtgzs27z5mwzhpmw244d00000gp/T/pip_build_cami/pyside
Storing complete log in /Users/cami/Library/Logs/pip.log

我尝试安装 cmake

camilo-mbp:mvc cami$ pip install cmake
Downloading/unpacking cmake
Could not find any downloads that satisfy the requirement cmake
Cleaning up...
No distributions at all found for cmake
Storing complete log in /Users/cami/Library/Logs/pip.log
camilo-mbp:mvc cami$ 

我还应该做什么?

提前致谢

【问题讨论】:

看来需要安装cmake... 好的,我试过没有成功(原帖已更新) 【参考方案1】:

据我所知,cmake 不是 python 包。它是一个构建工具。因此,您所要做的就是安装它。你可以从这里得到它:CMake site

另外,您应该检查 Apple 开发工具是否已经有 cmake。

【讨论】:

感谢评论,我已经用 brew install cmake 安装了 cmake,现在 qtconsole 正在工作【参考方案2】:

关于在 MacOSX 上构建和安装 PySide 的文档在这里 http://pyside.readthedocs.org/en/latest/building/macosx.html

【讨论】:

【参考方案3】:

问题陈述Qtconsole导入错误或冲突。

这是我得到的确切错误消息

File "uikit/ipython.py", line 5, in <module>
ImportError: No module named qt.console.rich_ipython_widget
[28603] Failed to execute script bosetap

Currently-imported Qt library: 'pyqt'
PyQt4 installed: False
PyQt5 installed: False
PySide >= 1.0.3 installed: False
PySide2 installed: False
Tried to load: ['pyqt']

您可以深入研究 uikit/ipython.py 并查看导入新旧库和以下内容的 try catch 块。

QT_API = os.environ.get('QT_API', None)
if QT_API not in [QT_API_PYSIDE, QT_API_PYSIDE2, QT_API_PYQT, QT_API_PYQT5, None]:
raise RuntimeError("Invalid Qt API %r, valid values are: %r, %r, %r, %r" %
(QT_API, QT_API_PYSIDE, QT_API_PYSIDE2, QT_API_PYQT, QT_API_PYQT5))
if QT_API is None:
api_opts = [QT_API_PYQT5, QT_API_PYSIDE2, QT_API_PYSIDE, QT_API_PYQT]
else:
api_opts = [QT_API]

步骤 1) 我开始在 python 提示符下手动运行,我确信 qt.console 安装正确。如果你发现你不能这样做。安装缺少的模块。

pip install qtconsole

第 2 步)如果您使用的是 pyqt4,请确保在您的 pyinstaller 规范文件中排除 pyqt5、pyside 和 pyside2 模块。它可能看起来像这样。这进入分析部分

excludes=['pyqtgraph.graphicsItems.PlotItem.plotConfigTemplate_pyqt5',
                'pyqtgraph.graphicsItems.PlotItem.plotConfigTemplate_pyqt5',
                'pyqtgraph.graphicsItems.ViewBox.axisCtrlTemplate_pyqt5',
                'pyqtgraph.GraphicsScene.exportDialogTemplate_pyqt5',
                'PyQt5',' PyQt5.QtCore','PyQt5.QtGui','PyQt5.QtPrintSupport',
                'PyQt5.QtSvg','PySide','PySide2'],

这可能有点矫枉过正。一旦我开始工作,我就不想碰它。优化留给读者练习。

Step3) 我会先告诉你解决方案,然后告诉你如何到达那里。问题是 pyinstaller 将我的 pyqt4 可执行文件放在包的顶层。 Qtconsole 在 PyQt4 目录中寻找它们。以下内容位于您的规范文件的 exe 部分。

a.binaries + [('PyQt4/QtCore.so','/usr/lib/python2.7/dist-packages
  PyQt/QtCore.so','BINARY'), ('PyQt4/QtGui.so','/usr/lib/python2.7/dist-packages
/PyQt4/QtGui.so','BINARY'), ('PyQt4/QtOpenGL.so','/usr/lib/python2.7/dist-packages 
/PyQt4/QtOpenGL.so','BINARY'), ('PyQt4/QtSvg.so','/usr/lib/python2.7/dist-packages
/PyQt4/QtSvg.so','BINARY'), ('PyQt4/QtTest.so','/usr/lib/python2.7/dist-packages
/PyQt4/QtTest.so','BINARY'), ('PyQt4/QtXml.so','/usr/lib/python2.7/dist-packages

/PyQt4/QtXml.so','BINARY') ],

所以,这个解决方案的坏处是我们现在收到警告说我们在两个地方有相同的可执行文件。优化留给读者作为练习。老实说,我还没有想出如何解决这个问题。所以,如果你这样做……很高兴收到你的来信。 这就是我进入第 3 步的方式。我认为这部分很重要。我将此添加到我的规范文件中只是为了开发,而不是为了客户的包。开发包的问题是它无法运行,然后 tmp/ 目录会自行删除。我看不出问题出在哪里。我知道我已经安装了 pyqt4 并且该应用程序是手动运行的。这非常令人沮丧。因此,如果您对规范文件执行以下操作,您将获得一个构建的目录而不是可执行文件。该目录仍然存在,您可以在里面看到发生了什么。然后,您已武装并危险地启用该解决方案。然后当你让它工作时,你恢复它为你的客户开发一个可执行文件。

  exe = EXE(pyz,
              a.scripts,
             [],
              exclude_binaries=True,
              name='bosetap',
              debug=False,
              bootloader_ignore_signals=False,
              strip=False,
              upx=True,
              console=True )

    coll = COLLECT(exe,
                   a.binaries,
                   a.zipfiles,
                   a.datas,
                   strip=False,
                   upx=True,
                   name='bosetap')

特别感谢我的老板,因为我为此努力了 1 周。快乐小径。

【讨论】:

以上是关于加载 ipython qtconsole 时出错的主要内容,如果未能解决你的问题,请参考以下文章

TensorFlow 在 Python CLI 和 IPython CLI 中导入,但不在 IPython QtConsole 中

如何运行连接到 ipython3 实例的 qtconsole?

运行外部文件时在 ipython qtconsole 中进行 LaTeX 打印

指定 ipython 配置文件 qtconsole

在 IPython qtconsole 中确定终端宽度

脚本执行后启动 ipython qtconsole 作为交互式解释器