python-greenlet / greenlet

Lightweight in-process concurrent programming
Other
1.63k stars 247 forks source link

Python 3.9: Greenlet errors on iPad #377

Closed nitantsoni closed 9 months ago

nitantsoni commented 10 months ago

I am trying to install Klipper on my iPad, using this repo - https://github.com/gio3k/DarwinPrint

When trying to launch Klippy, I get this error message

Traceback (most recent call last):
  File "/var/mobile/GitHub/DarwinPrint/Instance/klipper/klippy/klippy.py", line 8, in <module>
    import util, reactor, queuelogger, msgproto
  File "/private/var/mobile/GitHub/DarwinPrint/Instance/klipper/klippy/reactor.py", line 7, in <module>
    import greenlet
  File "/var/mobile/GitHub/DarwinPrint/Instance/environments/klipper/lib/python3.9/site-packages/greenlet/__init__.py", line 29, in <module>
    from ._greenlet import _C_API # pylint:disable=no-name-in-module
ImportError: dlopen(/var/mobile/GitHub/DarwinPrint/Instance/environments/klipper/lib/python3.9/site-packages/greenlet/_greenlet.cpython-39-darwin.so, 2): no suitable image found.  Did find:
    /var/mobile/GitHub/DarwinPrint/Instance/environments/klipper/lib/python3.9/site-packages/greenlet/_greenlet.cpython-39-darwin.so: file system sandbox blocked mmap() of '/var/mobile/GitHub/DarwinPrint/Instance/environments/klipper/lib/python3.9/site-packages/greenlet/_greenlet.cpython-39-darwin.so'

I tried out different versions of Greenlet v1.1.2, v2.0.1, v3.0.0, but all give me the same error. Even if I compile the package from source, by using the --no-binary flag, the error remains the same.

Compiled using these ENV vars

CPPFLAGS=-target arm64-apple-ios14.0 -isysroot /usr/share/SDKs/iPhoneOS.sdk

The .so file is also the correct architecture. Using lipo this is the output

input file lib/python3.9/site-packages/greenlet/_greenlet.cpython-39-darwin.so is not a fat file
Non-fat file: lib/python3.9/site-packages/greenlet/_greenlet.cpython-39-darwin.so is architecture: arm64

I am not sure what else to try

arcivanov commented 10 months ago

From the error message above kinda suggests it's not a compilation issue, I think:

file system sandbox blocked mmap()

jamadden commented 10 months ago

Right, this is not a greenlet issue per se, it's an issue loading native libraries. There's nothing greenlet can do about that.

nitantsoni commented 10 months ago

I donot think this is related to the mmap(). That error seems to be unrelated to the Greenlet error.

Checking some old issues & their error logs - here & here - it looks like Python is having trouble inspecting the architecture of the .so file, while generating the error message.

The message should have been something like

ImportError: dlopen(/Users/Roy/.local/share/virtualenvs/g10oal-JoGbQ0lv/lib/python3.9/site-packages/greenlet/_greenlet.cpython-39-darwin.so, 2): no suitable image found.  Did find:
    /Users/Roy/.local/share/virtualenvs/g10oal-JoGbQ0lv/lib/python3.9/site-packages/greenlet/_greenlet.cpython-39-darwin.so: mach-o, but wrong architecture
    /Users/Roy/.local/share/virtualenvs/g10oal-JoGbQ0lv/lib/python3.9/site-packages/greenlet/_greenlet.cpython-39-darwin.so: mach-o, but wrong architecture

but instead I get the mmap() error, where it should be telling me what the architecture of the .so is

ImportError: dlopen(/var/mobile/GitHub/DarwinPrint/Instance/environments/klipper/lib/python3.9/site-packages/greenlet/_greenlet.cpython-39-darwin.so, 2): no suitable image found.  Did find:
    /var/mobile/GitHub/DarwinPrint/Instance/environments/klipper/lib/python3.9/site-packages/greenlet/_greenlet.cpython-39-darwin.so: file system sandbox blocked mmap() of '/var/mobile/GitHub/DarwinPrint/Instance/environments/klipper/lib/python3.9/site-packages/greenlet/_greenlet.cpython-39-darwin.so'

I also had to compile Cpython, cffi & some other python modules and they all seem to be working fine. They were all compiled with the same toolchain & on the same iPad, so I assume that should be OK.

If I try to inspect the _greenlet.cpython-39-darwin.so file it also appears to be fine, and the functions, headers all appear to be in the correct format

Anyway thanks for looking at this. Think I'll just install Klipper on an old rPi or an old x86 machine.

nitantsoni commented 9 months ago

Got it working! Had to mess around with GCC flags. Specifically sysroot & library paths