Opened 11 years ago

Closed 6 years ago

#42512 closed defect (fixed)

Tkinter not working with macports-installed pypy

Reported by: macports.org@… Owned by: danchr (Dan Villiom Podlaski Christiansen)
Priority: Normal Milestone:
Component: ports Version: 2.2.1
Keywords: Cc:
Port: pypy

Description

With CPython or a pypy translated from source, $PYTHON -m Tkinter opens a small window with 2 buttons.

With macports's pypy, however:

> pypy -m Tkinter
Traceback (most recent call last):
  File "app_main.py", line 72, in run_toplevel
  File "/opt/local/lib/pypy/lib-python/2.7/runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/opt/local/lib/pypy/lib-python/2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/opt/local/lib/pypy/lib-python/2.7/lib-tk/Tkinter.py", line 39, in <module>
    import _tkinter # If this fails your Python may not be configured for Tk
  File "/opt/local/lib/pypy/lib_pypy/_tkinter/__init__.py", line 13, in <module>
    from .tklib import tklib, tkffi
  File "/opt/local/lib/pypy/lib_pypy/_tkinter/tklib.py", line 137, in <module>
    library_dirs = libdirs
  File "/opt/local/lib/pypy/lib_pypy/cffi/api.py", line 339, in verify
    lib = self.verifier.load_library()
  File "/opt/local/lib/pypy/lib_pypy/cffi/verifier.py", line 73, in load_library
    self._write_source()
  File "/opt/local/lib/pypy/lib_pypy/cffi/verifier.py", line 125, in _write_source
    file = open(self.sourcefilename, 'w')
IOError: [Errno 2] No such file or directory: '/opt/local/lib/pypy/lib_pypy/_tkinter/__pycache__/_cffi__g23e32416x3547cfed.c'

Reinstalling pypy does not fix the issue.

Change History (8)

comment:1 Changed 11 years ago by ryandesign (Ryan Carsten Schmidt)

Keywords: jmr@macports.org removed
Owner: changed from macports-tickets@… to jmr@…

comment:2 Changed 11 years ago by macports.org@…

Note: tried installing from source (port -s install pypy), same result.

comment:3 Changed 11 years ago by jmroot (Joshua Root)

Yes, the pypy port does not include tkinter.

comment:4 Changed 11 years ago by macports.org@…

Is there any specific reason? If it can't be fixed, can it be patched somehow to have import _tkinter raise ImportError instead of blowing up with IOError?

My original issue was actually trying to install Pillow whose setup.py performs a bunch of checks for available libraries. The tcl/tk support check it's a fairly common pattern:

try:
    import _tkinter
except ImportError:
    _tkinter = None

but because this yields an IOError the install fails entirely instead of simply marking tkinter as unavailable.

comment:5 Changed 11 years ago by jmroot (Joshua Root)

I don’t know why pypy doesn’t throw an ImportError in this case. I haven’t patched out tkinter support or anything so it’s just behaving in the default manner when the configuration process doesn’t find tk. If you can figure out how to fix the exception I could include a patch, though not necessarily before the next upstream release.

Adding tkinter support would be OK too if you know how, though probably in a variant since it does pull in libX11 and dependencies.

comment:6 Changed 7 years ago by jmroot (Joshua Root)

Owner: changed from jmroot to danchr
Status: newassigned

comment:7 Changed 6 years ago by danchr (Dan Villiom Podlaski Christiansen)

comment:8 Changed 6 years ago by danchr (Dan Villiom Podlaski Christiansen)

Resolution: fixed
Status: assignedclosed

In 327f4f85d2ab2d58c9a40d912b602410a472d65c/macports-ports (master):

pypy-tkinter: new port

Equivalent to 'py-tkinter', but for PyPy; uses the MacPorts-provided
Tcl & Tk frameworks.

Closes: #42512

Note: See TracTickets for help on using tickets.