1

I am using PyCharm 2017.2.3 and python 2.7 on Ubuntu 16.04. I am running into an issue trying to use matplotlib for plotting even a simple code as next one.

from matplotlib import pyplot as plt
import matplotlib.image as mpimg

image = mpimg.imread("chelsea-the-cat.png")
plt.imshow(image)
plt.show()

Apparently there is no errors or warnings, just the running script get stuck. But when using debug, the debug console print out this:

/home/esromerom/.virtualenvs/cv/bin/python /opt/pycharm-2017.2.3/helpers/pydev/pydevd.py --multiproc
--qt-support=auto --client 127.0.0.1 --port 45601 --file 
"/media/esromerom/TOSHIBA EXT/grado/cv/image.py" pydev debugger: process 14506 is connecting

Connected to pydev debugger (build 172.3968.37)
Failed to enable GUI event loop integration for 'tk'
Traceback (most recent call last):
  File "/opt/pycharm-2017.2.3/helpers/pydev/pydev_ipython/matplotlibtools.py", line 31, in do_enable_gui
    enable_gui(guiname)
  File "/opt/pycharm-2017.2.3/helpers/pydev/pydev_ipython/inputhook.py", line 528, in enable_gui
    return gui_hook(app)
  File "/opt/pycharm-2017.2.3/helpers/pydev/pydev_ipython/inputhook.py", line 278, in enable_tk
    app = _TK.Tk()
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1818, in __init__
    self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
TclError: couldn't connect to display "True"
Backend TkAgg is interactive backend. Turning interactive mode on.
TkAgg

I have already tried the recommended solutions for similar issues, but the script still no shows anything. (Check matplotlib Backend, re-install tk libraries, re-install matplotlib, add "DISPLAY=True" in Run/Debug Configurations, ...)

Does anybody have any idea of how make it happens?

1
  • Sorry, I will not be usefull. The same thing happens to me in Ubuntu 18.04 LTS. Glad to know I'm not the only one, but saddened that no solution seems to exist to this problem. Commented Jun 14, 2018 at 15:06

1 Answer 1

2

I've found a solution actually. The problem comes from the environment variable DISPLAY that is set to True.

In your terminal, run the command

echo $DISPLAY

For me, it is :0 I've then changed DISPLAY=True for DISPLAY=:0 and now matplotlib works for me. I've changed that in the "edit configuration" panel on the upper right I've changed the default configuration for Python, then deleted all previous configurations for my scripts.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.