为python2和python3构建matplotlib依赖项

我希望在我的计算机中有各种虚拟环境,其中一些运行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. 

怎么解决这个问题? 欢迎使用pipapt-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  import gobject ImportError: No module named 'gobject' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "", line 1, in  File "/home/oriol/venvs/pic_python3.5/lib/python3.5/site-packages/matplotlib/pyplot.py", line 115, in  _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  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']