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
self.tk = _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
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
matplotlib.use('Agg')
# force non-interactive mode, or set 'interactive' to False
# in your ~/.matplotlib/matplotlibrc
matplotlib.pyplot.ioff()
See also the following references:
What is a matplotlib backend
Customizing matplotlib with a matplotlibrc file
I just had the same problem, for those still interested: the existing answer is almost right, but the order is important: you need to call matplotlib.use before pyplot.
This worked for me:
import matplotlib
# force headless backend, or set 'backend' to 'Agg'
# in your ~/.matplotlib/matplotlibrc
matplotlib.use('Agg')
import matplotlib.pyplot
# force non-interactive mode, or set 'interactive' to False
# in your ~/.matplotlib/matplotlibrc
matplotlib.pyplot.ioff()
Related
Qt5Agg is necessary to use the mayavi 3D visualization package. I have installed PyQt5 and mayavi using pip in a separate copied conda environment. The default backend then changes from TkAgg to QtAgg. This is a bit weird because in an earlier installation in a different PC the default changed directly to Qt5Agg. I always check the backend using the following commands from the python console :
import matplotlib
matplotlib.get_backend()
Even with the backend being 'QtAgg', I am able to use mayavi from the terminal without any issue but not when I do so in Pycharm. Here I get a non-responsive empty window (image below) :
Image of the non-responsive window
I have been able to get rid of this issue by explicitly using Qt5Agg instead of QtAgg before the plt call :
import matplotlib
matplotlib.use('Qt5Agg')
import matplotlib.pyplot as plt
But I would prefer a better way than using the above in every script that I write. As I had mentioned earlier, I already have mayavi installed and have used it successfully it in Pycharm in a different PC and there the default backend is 'Qt5Agg' and hence there is no need to change the backend explicitly.
Is there anything obvious that I'm overlooking ? Can you please let me know of a way to change the default backend for matplotlib from QtAgg to Qt5Agg after PyQt5 installation using pip ?
Thanks in advance !!
Thanks to #PaulH's comment, I was able to solve the issue. Owing to #mx0's suggestion, I shall now explicitly mention the fix below so that others can also benefit from it.
In a particular conda environment, if matplotlib package is installed, then there will be a 'matplotlibrc' file stored somewhere that defines what the default backend will be whenever matplotlib is imported from that conda environment. The location of this 'matplotlibrc' can be found using the following commands :
import matplotlib
matplotlib.matplotlib_fname()
Please look into the following link if there's any deprecation issue with the above commands :
https://matplotlib.org/stable/tutorials/introductory/customizing.html#customizing-with-matplotlibrc-files
Once the location of the 'matplotlibrc' file is known, open it and simply uncomment one line inside this file. Just change the backend from :
##backend: Agg
to :
backend: Qt5Agg
And that's it. All the plot window troubles in PyCharm will be solved as far as the mayavi 3D visualization package is concerned. For any other use, where a specific backend is necessary, you can also set the default to any other backend of choice.
I just installed Intel Python Distribution with Anaconda. I was trying the plot some data but it plots on Web Browser and gives "Press Ctrl+C to stop WebAgg server" output also. I tried to change the backend using "plt.switch_backend('TkAgg')" and it worked and plotted in standard GUI Tkinter as I wanted. However I want to change the default configs of matplotlib not to put "plt.switch_backend('TkAgg')" everytime I plot something. Do you know how to do it?
Thanks in advance.
I'm trying out Jupyter console for the first time, but can't get the %matplotlib inline magic to work. Below is a screenshot of an example session:
The plot shows in a separate window after I run Line 6, and Line 7 doesn't do anything.
When I run %matplotlib --list, inline is given as one of the options:
Available matplotlib backends: ['osx', 'qt4', 'qt5', 'gtk3', 'notebook', 'wx', 'qt',
'nbagg', 'agg', 'gtk', 'tk', 'ipympl', 'inline']
When I try to use another backend, say qt5, it gives an error message because I don't have any Qt installed.
ImportError: Matplotlib qt-based backends require an external PyQt4, PyQt5, or PySide
package to be installed, but it was not found.
Running %matplotlib?? reads:
If you are using the inline matplotlib backend in the IPython Notebook
you can set which figure formats are enabled using the following::
In [1]: from IPython.display import set_matplotlib_formats
In [2]: set_matplotlib_formats('pdf', 'svg')
The default for inline figures sets `bbox_inches` to 'tight'. This can
cause discrepancies between the displayed image and the identical
image created using `savefig`. This behavior can be disabled using the
`%config` magic::
In [3]: %config InlineBackend.print_figure_kwargs = {'bbox_inches':None}
But I don't know if it's something I can tweak around to solve my issue.
When I try it the magic IPython console, it says inline is an Unknown Backend.
UnknownBackend: No event loop integration for u'inline'. Supported event loops are: qt,
qt4, qt5, gtk, gtk2, gtk3, tk, wx, pyglet, glut, osx
I've also found this issue on github after some googling but I don't even know if it's relevant to my situation (most of their conversation didn't make sense to me lol).
Lastly, I'm not sure if this issue is related at all, but here it is, just in case: when I try to open Vim in Jupyter via the !vim command, it glitches pretty badly, preventing me from even exiting out of Jupyter itself without closing the terminal altogther. Vim works perfectly fine when called inside IPython console, however.
I'm using matplotlib 2.0.0.
If anyone could help me figure this out, that'd be great! Thank you!
You’re running a console which is completely text based and incapable of showing images. Therefore, although inline is available, it's not producing inline output.
I'm not sure why it doesn't throw an error, though, which it does in my case:
You can use %matplotlib inline in a GUI console, like Jupyter QTConsole
or in a jupyter notebook in the browser
%matplotlib without the inline works for me (I'm using osx and IPython 7.0.1)
If you're running an old version of ipython try %pylab inline instead. See notes in this tutorial
I am trying to customize the Qt4Agg backend. To ensure that I didn't insert any bugs, as a starting point, I copied matplotlib/backends/backend_qt4agg.py to a new location on my PYTHONPATH, renamed it "my_backend.py", and corrected two import statements as follows:
from backend_agg import ...
from backend_qt4 import ...
becomes
from matplotlib.backends.backend_agg import ...
from matplotlib.backends.backend_qt4 import ...
In my matplotlib RC file I changed the backend to module://my_backend.py.
When plotting from a script using "show()", everything works as normal. But when trying to execute within an ipython session started with "ipython --pylab", the figure shows up, but nothing ever plots and I get a spinning wheel. How can I fix this?
I am using OSX Mavericks, Python 2.7.3, IPython 1.1.0, and Matplotlib 1.3.1.
Thanks
The problem occurs because the GUI main loop fails to start because IPython does not recognize the backend, and therefore, it doesn't know which GUI to use. This can be remedied by manually starting the GUI main loop in an IPython startup file. In ~/.ipython/profile_default/startup/my_backend_start_gui.py I placed the following code:
import matplotlib
if matplotlib.rcParams['backend'] == 'module://my_backend':
from IPython.lib.inputhook import enable_gui
enable_gui('qt4')
Now everything works fine.
I updated my python distribution yesterday to EPD 7.3-2 (64-bit). I am working on a mac with snow leopard.
Now the plot device of matplotlib is broken in at least two ways:
the "save" button doesn't work and makes the terminal or ipython crash and
the only way to see the figure is to have it in front of you, there is no python figure icon in the dock.
I did my homework and these same problems were reported here and here.
I tried to follow the instructions to fix this given in here, but this is the error that I get:
$python install_pythonw.py `which python`/../..
/Library/Frameworks/EPD64.framework/Versions/Current/.Python does not exist; exiting.
Indeed, I looked at the given folder and I could not find a .Python file. I added a comment at the answer to this problem but so far no one has replied to it :( :(
Any idea of how to fix this?
thanks!
I have seen this problem a few times, and it seems to be a problem in some backends. Also, it doesn't seem normal that your session crashes after 4 or 5 plots. In particular, the MacOSX backend seems buggy.
As you installed the EPD, I think it's less likely that your installation is broken.
The solution seems to be using a different backend. You can try with ipython --pylab a few backends, try their features and see if the save button works. You can try the following:
ipython --pylab=wx
ipython --pylab=tk
ipython --pylab=osx
The last one is the option that you're probably using right now, so perhaps not the best. If you just call ipython --pylab, it will use the default backend from your ~/.matplotlib/matplotlibrc file. Once you find a working backend you can change the default by editing that file. Look for a line like this:
backend : MacOSX
(your version may have a different backend.) Just change that setting to WXAgg, TkAgg, or Qt4Agg. With the --pylab option the names are slightly different, they don't have the Agg part. My favourite backend for OSX is the Qt4Agg backend, but I don't think it ships with EPD and the save button also doesn't work! But either WXAgg or TkAgg should work fine.
Other ways of changing the backend in a script are:
import matplotlib
matplotlib.use('WXAgg')
or
matplotlib.rcParams['backend'] = 'WXAgg'