![为 python2 和 python3 构建 matplotlib 依赖项](https://linux22.com/image/1156252/%E4%B8%BA%20python2%20%E5%92%8C%20python3%20%E6%9E%84%E5%BB%BA%20matplotlib%20%E4%BE%9D%E8%B5%96%E9%A1%B9.png)
我希望我的电脑中有各种虚拟环境,其中一些运行 python 2.7,另一些运行 python3,其中一些必须具有完整的 matplotlib 支持,这是在--system-syte-packages
创建虚拟环境时实现的(请参阅matplotlib 常见问题)。
因此,我需要为两个 Python 版本构建 matplotlib 的依赖项。我开始这样做:
sudo apt-get build-dep python-matplotlib
一切都安装正确,然后我尝试运行:
sudo apt-get build-dep python3-matplotlib
它什么也没做,只打印了以下消息:
Reading package lists... Done
Picking 'matplotlib' as source package instead of 'python3-matplotlib'
Reading package lists... Done
Building dependency tree
Reading state information... Done
0 to upgrade, 0 to newly install, 0 to remove and 6 not to upgrade.
如何解决这个问题?欢迎提供相关解决方案pip
。apt-get
编辑:
我可以在 python3 虚拟环境中毫无问题地安装 matplotlib,但是它不支持许多后端。例如:
>>> import matplotlib
>>> matplotlib.use('GTK')
>>> import matplotlib.pyplot as plt
Traceback (most recent call last):
File "/home/oriol/venvs/pic_python3.5/lib/python3.5/site-packages/matplotlib/backends/backend_gtk.py", line 17, in <module>
import gobject
ImportError: No module named 'gobject'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/oriol/venvs/pic_python3.5/lib/python3.5/site-packages/matplotlib/pyplot.py", line 115, in <module>
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "/home/oriol/venvs/pic_python3.5/lib/python3.5/site-packages/matplotlib/backends/__init__.py", line 62, in pylab_setup
[backend_name], 0)
File "/home/oriol/venvs/pic_python3.5/lib/python3.5/site-packages/matplotlib/backends/backend_gtk.py", line 21, in <module>
raise ImportError("Gtk* backend requires pygtk to be installed.")
ImportError: Gtk* backend requires pygtk to be installed.
尽管pip freeze
虚拟环境里面包含了pygobject==3.20.0
。我以为这pygobject
可能是 python2 ,但是sys.path
虚拟环境中的 是:
['', '/usr/lib/python35.zip', '/usr/lib/python3.5', '/usr/lib/python3.5/plat-x86_64-linux-gnu', '/usr/lib/python3.5/lib-dynload', '/home/oriol/venvs/pic_python3.5/lib/python3.5/site-packages', '/usr/local/lib/python3.5/dist-packages', '/usr/lib/python3/dist-packages']