senthilnathang senthilnathang - 6 months ago 65
Python Question

Python Tkinter issue using with ubuntu server

I have problem in using tkinter plugin.
I am using ubuntu 12.10 desktop in my local system and i installed python 2.7 and 3.2
I used tkinter plugin in OpenERP it works fine in my local pc.
But the problem is when use same code in server (Ubuntu 12.04 Server) it doesn't works

It shows = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk,sync, use)
TclError: no display name and no $DISPLAY environment variable

I check with python in terminal also it says error it means there is problem in tkinter
somewhere i dont know.
I also checked for tkinter and python versions both are good.
But i find some thing unusual while locating tkinter in terminal.
In Local it show tkinter plugin located in python3.2,
But in the server it doesn't show the tkinter

I checked the permission also it's fine.
How to make tkinter working in Ubuntu server 12.04

Answer Source

It would have been nice to include the full traceback and a larger code extract. The error message means that Tkinter is unable to find your X graphical environment, which likely means you're running the code on a headless server, as Dominic pointed out. You could try to install X on the server, but there's no need for a GUI if the machine is really meant to be a server with no user interface.

If you do need to display a GUI when that code is executed, then it should either not run on the server-side or you need to setup X11-forwarding to the client machine. This does not seem to make a lot of sense in an OpenERP context though - as it would hardly work in a generic manner for all users.

Now are you perhaps using matplotlib to produce graphics (your code extract does not show that)? If yes, you can simply force it to use a headless backend for producing the images, as explained in this question or this other question.

Try to have the following code executed before the rendering code is called:

import matplotlib
import matplotlib.pyplot

# force headless backend, or set 'backend' to 'Agg'
# in your ~/.matplotlib/matplotlibrc

# force non-interactive mode, or set 'interactive' to False
# in your ~/.matplotlib/matplotlibrc

See also the following references:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download