Skip to content

No output from pyplot on cygwin64 python3 virtualenv #5962

Closed

Description

@s7726

Encountered initially trying to work with:
https://github.com/amueller/word_cloud/blob/master/examples/simple.py

Then tried the matplotlib xkcd example.

I run the file python xkcd.py and the command runs, and returns (0 exit status), but no windows are displayed and no errors are given.

I'm running the latest cygwin x64 with a virtualenv running python 3.4.3 and matplotlib 1.5.1

I'm willing to help hunt down the issue. But I don't know where to start.

Activity

  1. WeatherGod commented on Feb 3, 2016

    @WeatherGod
    Member

    How did you install/build matplotlib? Chances are, if you built it from
    source, then you didn't have the gui headers available, so it fell back to
    a default of the headless AGG backend.

    On Tue, Feb 2, 2016 at 8:31 PM, Gavin S notifications@github.com wrote:

    Encountered initially trying to work with:
    https://githubcom/amueller/word_cloud/blob/master/examples/simplepy

    Then tried the matplotlib xkcd example

    I run the file python xkcdpy and the command runs, and returns (0 exit
    status), but no windows are displayed and no errors are given

    I'm running the latest cygwin x64 with a virtualenv running python 343 and
    matplotlib 151

    I'm willing to help hunt down the issue But I don't know where to start

    —
    Reply to this email directly or view it on GitHub
    #5962.

  2. s7726 commented on Feb 3, 2016

    @s7726
    ContributorAuthor

    I installed using pip install matplotlib. Is there a particular set of libraries or dev packages I should be looking for to install?
    Some kind of warning or something would be nice, when it's defaulting to a perceived inoperable mode.

  3. added this to the milestone on Feb 14, 2016
  4. tacaswell commented on Feb 14, 2016

    @tacaswell
    Member

    What does

    import matplotlib
    print(matplotlib.get_backend())

    give you? My guess is that it is going to say 'Agg', which is a non interactive backend. My guess is that you are missing a gui-toolkit wrapping library.

  5. s7726 commented on Mar 1, 2016

    @s7726
    ContributorAuthor

    Qt5Agg

    What should I have available for it to use something else?
    It would be nice if there were some kind of prompt or message to indicate defaulting to a non-functional (from user perspective) behavior.

  6. tacaswell commented on Mar 2, 2016

    @tacaswell
    Member

    Are you using plain python or ipython with %matplotlib magic.

    There are many use cases for mpl where an interactive backend is not desired so we can not guess when the lack of one is intentional or not.

    Does pyqt5 import cleanly?

    Try

    import matplotlib
    import matplotlib.pyplot as plt
    print(matplotlib.get_backend())
    plt.plot(range(3))
    plt.show()
    
  7. AmeyaVS commented on Mar 9, 2017

    @AmeyaVS

    I am also facing similar issue under cygwin.

    Initially when I installed matplotlib-2.0.0 in python-2.7 which is working fine.
    But when I moved to python-3.4.5 suddenly the sample applications also stopped working.
    After looking into dependencies and found out that the python3-tkinter backend was missing.

    After installing all the dependencies and rebuilding I am getting this error:

    >>> import matplotlib.pyplot as plt
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "$HOME/.local/lib/python3.4/site-packages/matplotlib/pyplot.py", line 115, in <module>
        _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
      File "$HOME/.local/lib/python3.4/site-packages/matplotlib/backends/__init__.py", line 32, in pylab_setup
        globals(),locals(),[backend_name],0)
      File "$HOME/.local/lib/python3.4/site-packages/matplotlib/backends/backend_tkagg.py", line 13, in <module>
        import matplotlib.backends.tkagg as tkagg
      File "$HOME/.local/lib/python3.4/site-packages/matplotlib/backends/tkagg.py", line 9, in <module>
        from matplotlib.backends import _tkagg
    RuntimeError: No such process

    After poking around my local installation for both python-2.7 and python-3.4.5 packages these are the differences I found in the libraries built:

    Python-2.7:

    $HOME/.local/lib/python2.7/site-packages/matplotlib/backends/_tkagg.dll

    Python-3.4.5:

    $HOME/.local/lib/python3.4/site-packages/matplotlib/backends/_tkagg.cpython-34m.dll

    It seems while importing the _tkagg package it looks for the _tkagg.dll

    Is there a way I can suppress the "cpython-34m" in the generated library? or
    Should I file a bug request at Cygwin for reporting this behaviour for the build?

    Note: I am using pip3 for managing the python libraries.

    Update: It was too pre-mature comment on my end, even after renaming the '_tkagg.cpython-34m.dll' to '_tkagg.dll' I am seeing the same error mentioned above.

  8. KptainBiwouak commented on Oct 11, 2017

    @KptainBiwouak

    I am facing exactly same kind of issue after trying to build Matplolib (v2.0.2 & v2.1.0).
    Build is successfull but Import _tkagg fails

    Could you provide us some guidelines in order to be able to use this module?
    Which dependencies are exactly required?
    Note: I am working from Cygwin 2.9.0 (x64) + Python 3.6.1

  9. matthew-brett commented on Oct 11, 2017

    @matthew-brett
    Contributor

    @KptainBiwouak - what do you get for:

    >>> import tkinter
    

    in Python?

  10. KptainBiwouak commented on Oct 11, 2017

    @KptainBiwouak

    Using Python 3.6.1, I got no error.
    It works.
    I am using default python3-tkinter-3.6.1-1 module provided from Cygwin packages

  11. lharcke commented on Jun 27, 2018

    @lharcke

    Same RuntimeError here from an install on Cygwin 64-bit via pip3 install --home matplotlib

    
    $ uname -a
    CYGWIN_NT-10.0 <hostname> 2.10.0(0.325/5/3) 2018-02-02 15:16 x86_64 Cygwin
    
    $ ipython3
    Python 3.6.4 (default, Jan  7 2018, 15:53:53)
    
    In [1]: import matplotlib
    
    In [6]: matplotlib.__version__
    Out[6]: '2.2.2'
    
    In [7]: import matplotlib.pyplot as plt
    ---------------------------------------------------------------------------
    RuntimeError                              Traceback (most recent call last)
    <ipython-input-7-eff513f636fd> in <module>()
    ----> 1 import matplotlib.pyplot as plt
    
    /home/lharcke/.local/lib/python3.6/site-packages/matplotlib/pyplot.py in <module>()
        113 ## Global ##
        114
    --> 115 _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
        116
        117 _IP_REGISTERED = None
    
    /home/lharcke/.local/lib/python3.6/site-packages/matplotlib/backends/__init__.py in pylab_setup(name)
         60     # imports. 0 means only perform absolute imports.
         61     backend_mod = __import__(backend_name, globals(), locals(),
    ---> 62                              [backend_name], 0)
         63
         64     # Things we pull in from all backends
    
    /home/lharcke/.local/lib/python3.6/site-packages/matplotlib/backends/backend_tkagg.py in <module>()
          2
          3 from .. import cbook
    ----> 4 from . import tkagg  # Paint image to Tk photo blitter extension.
          5 from .backend_agg import FigureCanvasAgg
          6 from ._backend_tk import (
    
    /home/lharcke/.local/lib/python3.6/site-packages/matplotlib/backends/tkagg.py in <module>()
          7 import numpy as np
          8
    ----> 9 from matplotlib.backends import _tkagg
         10
         11 def blit(photoimage, aggimage, bbox=None, colormode=1):
    
    RuntimeError: No such process
    
    In [8]: import tkinter
    
    In [9]: tkinter.TkVersion
    Out[9]: 8.6
    
    In [10]: tkinter.TclVersion
    Out[10]: 8.6
    

    Now to test tkinter:

    In [1]: import tkinter
    
    In [2]: root = tkinter.Tk()
    
    In [3]: w = tkinter.Label(root, text="hello, world.")
    
    In [4]: w.pack()
    
    In [5]: root.mainloop()
    
    [Window pops up with "hello, world." text]
    

    Here's the matplotlib back end:

    In [8]: print(matplotlib.get_backend())
    TkAgg
    

    So, tkinter seems to be installed properly, and the "hello, world." example works. But interactive plotting with matplotlib fails.

    Can also generate the error simply by issuing:

    In [11]: from matplotlib.backends import _tkagg
    ---------------------------------------------------------------------------
    RuntimeError                              Traceback (most recent call last)
    <ipython-input-11-874272889e03> in <module>()
    ----> 1 from matplotlib.backends import _tkagg
    
    RuntimeError: No such process
    

    But then https://matplotlib.org/users/installing.html says:

    Optionally, you can also install a number of packages to enable better user interface toolkits. See What is a backend? for more details on the optional Matplotlib backends and the capabilities they provide.

    tk (>= 8.3, != 8.6.0 or 8.6.1): for the TkAgg backend;
    PyQt4 (>= 4.4) or PySide: for the Qt4Agg backend;
    PyQt5: for the Qt5Agg backend;
    pygtk (>= 2.4): for the GTK and the GTKAgg backend;
    wxpython (>= 2.9 or later): for the WX or WXAgg backend;
    cairocffi (>= v0.8): for cairo based backends;
    pycairo: for GTK3Cairo;
    Tornado: for the WebAgg backend;

    So maybe matplotlib Just Doesn't Work with Tk version 8.6 (why not?)

  12. WeatherGod commented on Jun 28, 2018

    @WeatherGod
    Member
  13. lharcke commented on Jun 28, 2018

    @lharcke

    Python3. pip3, Tcl/Tk and Tkinter were installed via the Cygwin package manager. Matplotlib is not packaged for Cygwin, so I did:

    pip3 install --home matplotlib

    It would seem there is a known incompatibility between Matplotlib and Tk version 8.6, but the pip3 install doesn't check and warn about Tk 8.6 incompatibility and disable TkAgg if Tk 8.6 is present when attempting to build/install the TkAgg interface. At least nothing appeared on the command line during a pip3 install --home matplotlib install. It is possible if I threw the -v switch, there might have been some sort of warning generated.

  14. 1 remaining item

  15. lharcke commented on Jun 28, 2018

    @lharcke

    Remotely possible, as I have an Anaconda 4.2 Windows installation with Tkinter in C:\Program Files\Anaconda3\. But that would be very weird. Usually programs running under Cygwin ignore everything outside of the C:\cygwin64\ root directory. The pseudo-UNIX environment doesn't really permit programs to look above the pseudo-UNIX filesystem root, unless they explicitly try to access the mount point /cygdrive/c/. But UNIX programs generally don't know about the /cygdrive/c/ mount point, unless they are written specifically as Cygwin utilities/applications.

    Anyway, Matplotlib isn't packaged for Cygwin, and a pip3 install of Matplotlib doesn't work out of the box for some reason (most likely Tk 8.6 incompatibility), which isn't flagged/reported during the pip3 build/install.

  16. lharcke commented on Jun 28, 2018

    @lharcke

    So, here's the bit from setupext.py where the TkAgg build is prepared:

    class BackendTkAgg(OptionalBackendPackage):
        name = "tkagg"
        force = True
    
        def check(self):
            return "installing; run-time loading from Python Tcl / Tk"
    
        def runtime_check(self):
            """ Checks whether TkAgg runtime dependencies are met
            """
            try:
                import tkinter
            except ImportError:
                return False
            return True
    
    [snip]
    
        def add_flags(self, ext):
            ext.include_dirs.insert(0, 'src')
            if sys.platform == 'win32':
                # PSAPI library needed for finding Tcl / Tk at run time
                ext.libraries.extend(['psapi'])
            elif sys.platform == 'linux':
                ext.libraries.extend(['dl'])
    

    From static inspection, on current Cygwin, tkinter will load when runtime_check() is called. But it would appear that the add_flags() method will fail to add a dynamic linker for Cygwin, as on Cygwin, the call to sys.platform returns

    In [1]: import sys
    
    In [2]: sys.platform
    Out[2]: 'cygwin'
    

    and cygwin is not in the if/elif check for dynamic linker flags.

    Glancing through the rest of the installer script, it appears there are many tests of sys.platform for w32, darwin, linux, sunos5, aix5 and such, but none for cygwin. Also, there doesn't appear to be a check for specific versions of Tcl/Tk anywhere in the code.

    My guess at the bugfix is someone would have to spend some time editing the setupext.py script to add cygwin as a specific supported flavor of UNIX, and also to beef up the version number checking for Tcl/Tk, if indeed the Tk requirement is >= 8.3 but not 8.6 or 8.6.1 per the Matplotlib install webpage. I do not see the general mechanism where the matplotlib installer script checks/verifies version numbers of dependencies.

  17. Sonic-Amiga commented on May 13, 2020

    @Sonic-Amiga
    Contributor

    Hello! Just hit the same problem and using the git master branch figured out what's wrong. Apparently Windows doesn't provide for RTLD_LOCAL / RTLD_GLOBAL semantics , so Cygwin's dlsym() against /usr/lib/python3.6/lib-dynload/_tkinter.cpython-36m-x86_64-cygwin.dll fails to locate Tk_FindPhoto symbol, which is in fact declared in /usr/bin/libtk8.6.dll, despite all the dependencies are in place.
    It looks like we'll have to use Windows-native mechanism for symbol lookup for Cygwin.

  18. tacaswell commented on May 13, 2020

    @tacaswell
    Member

    @Sonic-Amiga Do you know what those mechanisms are and if so could you open a Pull Request with the changes?

    I don't think we currently test cygwin, but I suspect it would be possible on either appveyor or azure?

  19. Sonic-Amiga commented on May 14, 2020

    @Sonic-Amiga
    Contributor

    @tacaswell I've sucessfully verified that you can use native Windows API, the same as for "raw" Win32 platform. In src/_tkagg.cpp you have several #ifdef _WIN32. Those ones related to symbol loading should become #if defined(_WIN32) || defined(CYGWIN). And link against psapi library for cygwin platform. Yes, Cygwin apps are not advised to use WinAPI directly, but you're using it with care here. :) An alternate solution would be to implement POSIX behavior in cygwin1.dll; and i'm not sure how difficult it would be. At least there's no quick solution to that.
    Bear in mind that GetForegroundWindow/SetForegroundWindow should stay _WIN32-only since Cygwin, being an "honest" POSIX, uses X Window API for graphics.

  20. added a commit that references this issue on May 14, 2020
  21. Sonic-Amiga commented on May 14, 2020

    @Sonic-Amiga
    Contributor

    @tacaswell Please consider the PR. I've verified it with xkcd.py; it works.

  22. added a commit that references this issue on May 14, 2020
  23. QuLogic commented on May 15, 2020

    @QuLogic
    Member

    Fixed by #17415 (I can't test though.)

  24. modified the milestones: , v3.3.0 on May 15, 2020
  25. philgoetz commented on Jun 29, 2020

    @philgoetz

    I wrote a Python program that worked under cygwin python3.7 from late April through the end of May. I ran it again today and got the exact same error described here.
    I can't tell you what backend it's using because:

    $ python3
    Python 3.7.7 (default, Apr 10 2020, 07:59:19)
    [GCC 9.3.0] on cygwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import matplotlib
    >>> print(matplotlib.get_backend())
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/lib/python3.7/site-packages/matplotlib/__init__.py", line 1302, in get_backend
        return rcParams['backend']
      File "/usr/lib/python3.7/site-packages/matplotlib/__init__.py", line 831, in __getitem__
        from matplotlib import pyplot as plt
      File "/usr/lib/python3.7/site-packages/matplotlib/pyplot.py", line 2282, in <module>
        switch_backend(rcParams["backend"])
      File "/usr/lib/python3.7/site-packages/matplotlib/__init__.py", line 832, in __getitem__
        plt.switch_backend(rcsetup._auto_backend_sentinel)
      File "/usr/lib/python3.7/site-packages/matplotlib/pyplot.py", line 204, in switch_backend
        switch_backend(candidate)
      File "/usr/lib/python3.7/site-packages/matplotlib/pyplot.py", line 221, in switch_backend
        backend_mod = importlib.import_module(backend_name)
      File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
      File "/usr/lib/python3.7/site-packages/matplotlib/backends/backend_tkagg.py", line 1, in <module>
        from . import _backend_tk
      File "/usr/lib/python3.7/site-packages/matplotlib/backends/_backend_tk.py", line 22, in <module>
        from . import _tkagg
    RuntimeError: No such process
    
    

    I didn't use Python for anything else since the last time I ran my program.
    I did, however, run Cygwin's auto-update several times since then.
    I definitely also ran Cygwin's auto-update sometime in May, before running my program successfully.
    So some Cygwin update released in May or June is causing this error again.

    I recall that, in April, I initially installed python 3.8, but uninstalled it because I couldn't get seaborn to work. I don't remember if it was the same _tkagg error.

  26. tacaswell commented on Jun 29, 2020

    @tacaswell
    Member

    @philgoetz Try re-installing Matplotlib (you have have changed Tk under it?). If that fails can you try pip install --upgrade --pre matplotlib to try out 3.3.0rc1 which has the changes that closed this issue.

  27. philgoetz commented on Jun 29, 2020

    @philgoetz

    I found this comment on stackoverflow by me, describing the earlier problem:

    I'm having the exact same problem, with Python 3.7. Already installed tcl-tk-devel via the cygwin setup. Note the import statement specifies that _tkagg must be in (for me) /usr/lib/python3.7/site-packages/matplotlib/backends . And it is there! File _tkagg.cpython-37m-x86_64-cygwin.dll . For some reason the import fails to load it. – Phil Goetz Apr 2 at 20:50

    And I found this solution, which I had written down in my notes, copied from #5962

    It would seem there is a known incompatibility between Matplotlib and Tk version 8.6, but the pip3 install doesn't check and warn about Tk 8.6 incompatibility and disable TkAgg if Tk 8.6 is present when attempting to build/install the TkAgg interface. At least nothing appeared on the command line during a pip3 install --home matplotlib install. It is possible if I threw the -v switch, there might have been some sort of warning generated.

    So I reverted cygwin64 package tk-devel from Tk 8.6 to 8.5.11-1 .
    (This reversion didn't work for cygwin 32-bit, BTW; it complained that it couldn't download package 'freeglut'.)
    But I kept getting the same _tkagg error.

    I tried re-installing matplotlib, and in poking around discovered that my cygwin pip3 is, apparently, installing packages in my Anaconda3 install of python3.7, not my cygwin install of python3.7. Then I remembered that that had been my solution: I had to run my program inside an Anaconda3 window, using Anaconda's python. So I did that, and my program worked. I still haven't been able to get it run with Cygwin's python3.7 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions