【发布时间】:2017-01-27 17:02:40
【问题描述】:
我在 python 3.6(在 Xubuntu 16.04 中)下使用 pip (9.0.1) 安装了 ipython 和 matplotlib,但是当我尝试绘制某些东西时没有显示图像。
使用ipython3 --matplotlib qt 启动 ipython 会出现以下错误:
ImportError: Matplotlib qt-based backends require an external PyQt4, PyQt5,
or PySide package to be installed, but it was not found.
我尝试使用 pip 安装这些,但失败了:
$ pip3.6 install PySide
Collecting PySide
Downloading PySide-1.2.4.tar.gz (9.3MB)
100% |████████████████████████████████| 9.3MB 12.8MB/s
Complete output from command python setup.py egg_info:
only these python versions are supported: [(2, 6), (2, 7), (3, 2), (3, 3), (3, 4)]
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-bzzpzy5q/PySide/
$ pip3.6 install PyQT
Collecting PyQT
Could not find a version that satisfies the requirement PyQT (from versions: )
No matching distribution found for PyQT
$ pip3.6 install PyQT4
Collecting PyQT4
Could not find a version that satisfies the requirement PyQT4 (from versions: )
No matching distribution found for PyQT4
$ pip3.6 install PyQT5
Collecting PyQT5
Could not find a version that satisfies the requirement PyQT5 (from versions: )
No matching distribution found for PyQT5
如果我尝试ipython3 --matplotlib gtk,错误是:
ImportError: Gtk* backend requires pygtk to be installed.
但是:
$ pip3.6 install pygtk
Collecting pygtk
Could not find a version that satisfies the requirement pygtk (from versions: )
No matching distribution found for pygtk
我似乎明白 PyGobject 或 PyGI 取代了 python 3 的 pygtk。事实上,ipython3 --matplotlib gtk3 导致:
ImportError: Gtk3 backend requires pygobject to be installed.
但是:
$ pip3.6 install pygobject
Collecting pygobject
Could not find a version that satisfies the requirement pygobject (from versions: )
No matching distribution found for pygobject
$ pip3.6 install PyGObject
Collecting PyGObject
Could not find a version that satisfies the requirement PyGObject (from versions: )
No matching distribution found for PyGObject
终于pip3.6 install PyGI成功了!
但是 matplotlib 仍然抱怨没有安装 GTK 的东西。
我还应该尝试什么?
【问题讨论】:
-
我试图放置 python3.6 标签,但我没有足够的声誉。如果有人认为它有用并且有足够的声誉,请不要犹豫,将我的 3.x 标签替换为 3.6 标签。
-
即使没有 GTK 或 PyQt matplotlib 也应该可以工作。尝试在 ipython 中使用
ipython3 --matplotlib tk或在脚本中使用import matplotlibmatplotlib.use("TkAgg")。对于有关安装 pyqt 或 GTK 的解决方案,您使用的操作系统、您拥有的 pip 版本等非常重要,因此您可能希望将此信息添加到问题中。 -
尝试
ipython3 --matplotlib tk得到ModuleNotFoundError: No module named '_tkinter'。安装 tk-dev (stackoverflow.com/a/5459492/1878788) 后,我正在重新编译 python 3.6。 -
只是提一下,以防你不知道:你总是可以去一个完整的发行版,比如anaconda,它有你需要的一切。
-
重新编译 tk-dev 安装使我能够让 Tk 后端工作。您可以发布您的建议作为答案。在我的情况下,它是相关且有用的。谢谢。
标签: qt python-3.x matplotlib gtk pip