Using matplotlib on a Ubuntu 14.04 headless server

I have a server without an Ubuntu 14.04 Server header that I connect to remotely using SSH. I want to use matplotlib and display graphs in an ssh client. For example, I would connect using:

ssh -X name@server.com 

And then from the Python console, I want this to create a plot in a window:

 import matplotlib.pyplot as plt plt.plot(range(10)) plt.show() 

I installed matplotlib in my virtualenv and I ran sudo apt-get install python-gtk2 but the plot still doesn't appear. I guess I have a lot of packages. What is the pretty minimal set of X-related packages I could install to make this work? I do not want to install ubuntu-desktop .

+5
source share
1 answer

I was working on a Ubuntu server 14.04.1, but it was painful! The hard part is, of course, virtualenv. I was finally lucky using the Qt4 backend, which I could only install through the Ubuntu package, and then had to symbolically link it to my virtualenv. So, here is a step by step process ...

Install pre-reqs first and hack PyQt4 into your 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 ) by activating your venv as follows:

 $ tar xzf sip-4.16.4.tar.gz $ cd sip-4.16.4 $ python configure.py $ make $ sudo make install 

Then download the tarplotlib source tarball and change the configuration setting to force it to install the Qt4 backend:

 $ 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 next to line 68 as follows:

 qt4agg = True 

Matplotlib will now automatically install in your vein:

 $ pip install -e matplotlib-1.4.2/ 

Now you can use SSH with the -X flag, and the graphics will load remotely!

+3
source

Source: https://habr.com/ru/post/1206457/


All Articles