Archive

Posts Tagged ‘tkinter’

[matplotlib] create figures on a remote server

October 16, 2016 Leave a comment

Problem
On a remote server of mine I wanted to create some nice figures with matplotlib. It worked well on localhost but it failed on the server. First, tkinter was missing. Second, there was a problem with $DISPLAY.

Solution
To install tkinter, check out this earlier post.

The second problem is caused by a missing X server. On a remote server usually there is no graphical interface. To solve it, just add these two lines to the top of your program:

import matplotlib as mpl
mpl.use('Agg')

Example
Before:

#!/usr/bin/env python3
# coding: utf-8

import pylab
import numpy as np

def main():
    x = np.arange(-3.14, 3.14, 0.01)
    y = np.sin(x)
    pylab.plot(x, y, "b")
    pylab.savefig("out.png")

##############################################################################

if __name__ == "__main__":
    main()

After:

#!/usr/bin/env python3
# coding: utf-8

import matplotlib as mpl
mpl.use('Agg')

import pylab
import numpy as np

def main():
    x = np.arange(-3.14, 3.14, 0.01)
    y = np.sin(x)
    pylab.plot(x, y, "b")
    pylab.savefig("out.png")

##############################################################################

if __name__ == "__main__":
    main()

Output:
sine

Categories: matplotlib, python Tags: , , ,

a simple GUI pomodoro timer

For managing my TODO lists, I use a sheet of paper where I make a list of tasks to do. A few days ago I started to use the pomodoro technique, which helps a lot to actually DO those tasks :)

As I don’t have a tomato-shaped kitchen timer (yet!), I wrote a simple GUI timer that you can find on github.

Update (20160608)
Here is an online timer: http://www.timeanddate.com/timer/. It can play a sound, and you can also launch several timers if you want. Thanks Jeszy for the link.

“import tkinter” fails

April 27, 2016 Leave a comment

Problem
Under Manjaro I wanted to use the turtle module but I got this error:

File "square.py", line 1, in <module>
    import turtle
  File "/usr/lib/python2.7/lib-tk/turtle.py", line 107, in <module>
    import Tkinter as TK
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 39, in <module>
    import _tkinter # If this fails your Python may not be configured for Tk
ImportError: libtk8.6.so: cannot open shared object file: No such file or directory

Solution

sudo pacman -S tk

Ubuntu 14.04
I had the same problem under Ubuntu when I tried to use matplotlib on a remote server.

sudo apt install python3-tk
Categories: python, ubuntu Tags: , , ,