[英]Using matplotlib on headless Ubuntu 14.04 Server
I have a headless Ubuntu 14.04 Server that I connect to remotely using SSH. 我有一个无头的Ubuntu 14.04服务器,我使用SSH远程连接。 I want to use matplotlib and have plots appear at the ssh client.
我想使用matplotlib并在ssh客户端上显示图。 For example, I would connect using:
例如,我将连接使用:
ssh -X name@server.com
And then from a Python console, I want this to produce a plot in a window: 然后从Python控制台,我希望这在窗口中生成一个图:
import matplotlib.pyplot as plt
plt.plot(range(10))
plt.show()
I have installed matplotlib in my virtualenv, and I ran sudo apt-get install python-gtk2
, but the plot still doesn't appear. 我已经在我的virtualenv中安装了matplotlib,我运行了
sudo apt-get install python-gtk2
,但是剧情仍然没有出现。 I assume I'm missing lots of packages. 我想我错过了很多包。 What is a fairly minimal set of X-related packages I could install to make this work?
什么是我可以安装的相关最小的X相关软件包,以使其工作? I do NOT want to install
ubuntu-desktop
. 我不想安装
ubuntu-desktop
。
I got it working on Ubuntu 14.04.1 Server, but it was painful! 我得到了它在Ubuntu 14.04.1服务器上的工作,但它很痛苦! The tricky part is definitely virtualenv.
棘手的部分绝对是virtualenv。 I finally had luck using the Qt4 backend, which I was only able to install via the Ubuntu package and then had to symlink it into my virtualenv.
我终于运气了Qt4后端,我只能通过Ubuntu软件包安装,然后不得不将它符号链接到我的virtualenv。 So here's the step-by-step process...
所以这是一步一步的过程......
First install the pre-reqs and hack PyQt4 into your virtualenv: 首先安装pre-req并将PyQt4入侵你的virtualenv:
$ sudo apt-get install xauth x11-apps python-qt4
$ ln -s /usr/lib/python2.7/dist-packages/PyQt4 /path/to/myvenv/lib/python2.7/PyQt4
Now manually download and install SIP ( http://www.riverbankcomputing.com/software/sip/intro ) with your venv activated, as follows: 现在手动下载并安装SIP( http://www.riverbankcomputing.com/software/sip/intro )并激活您的venv,如下所示:
$ tar xzf sip-4.16.4.tar.gz
$ cd sip-4.16.4
$ python configure.py
$ make
$ sudo make install
Next, download matplotlib source tarball and modify the setup configuration to force it to install Qt4 backend: 接下来,下载matplotlib源码tarball并修改安装配置以强制它安装Qt4后端:
$ tar xzf matplotlib-1.4.2.tar.gz
$ cp matplotlib-1.4.2/setup.cfg.template matplotlib-1.4.2/setup.cfg
Now edit setup.cfg
near line 68 to read: 现在编辑第68行附近的
setup.cfg
来读取:
qt4agg = True
Matplotlib will now install cleanly in your venv: Matplotlib现在将在您的venv中干净利落地安装:
$ pip install -e matplotlib-1.4.2/
Now you can SSH using the -X
flag and plots will load remotely! 现在您可以使用
-X
标志进行SSH,并且图表将远程加载!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.