Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when compiling Cython: Cannot convert 'unsigned int *' to Python object #9

Closed
twaslowski opened this issue Jul 2, 2024 · 5 comments

Comments

@twaslowski
Copy link

twaslowski commented Jul 2, 2024

Hey! First off, I think this is a super cool project. Thanks a lot for all of your work!

Unfortunately, the installation is broken for me.
When running pip3 install gambaterm, I get an error when building the gambaterm wheel. The full compiler stacktrace:

  ERROR: Command errored out with exit status 1:
   command: /Users/tobias.waslowski/projects/personal/gambaterm/venv/bin/python3 /Users/tobias.waslowski/projects/personal/gambaterm/venv/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py build_wheel /var/folders/fc/j5c56kcn0rj1kx27qbwj8mvw0000gp/T/tmpia2aafu7
       cwd: /private/var/folders/fc/j5c56kcn0rj1kx27qbwj8mvw0000gp/T/pip-install-jiydfwsf/gambaterm_a9b39a9344ef4a49a377734962d452e5
  Complete output (209 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.macosx-10.9-universal2-cpython-39
  creating build/lib.macosx-10.9-universal2-cpython-39/gambaterm
  copying gambaterm/console.py -> build/lib.macosx-10.9-universal2-cpython-39/gambaterm
  copying gambaterm/run.py -> build/lib.macosx-10.9-universal2-cpython-39/gambaterm
  copying gambaterm/keyboard_input.py -> build/lib.macosx-10.9-universal2-cpython-39/gambaterm
  copying gambaterm/__init__.py -> build/lib.macosx-10.9-universal2-cpython-39/gambaterm
  copying gambaterm/ssh_app_session.py -> build/lib.macosx-10.9-universal2-cpython-39/gambaterm
  copying gambaterm/file_input.py -> build/lib.macosx-10.9-universal2-cpython-39/gambaterm
  copying gambaterm/audio.py -> build/lib.macosx-10.9-universal2-cpython-39/gambaterm
  copying gambaterm/controller_input.py -> build/lib.macosx-10.9-universal2-cpython-39/gambaterm
  copying gambaterm/ssh.py -> build/lib.macosx-10.9-universal2-cpython-39/gambaterm
  copying gambaterm/main.py -> build/lib.macosx-10.9-universal2-cpython-39/gambaterm
  copying gambaterm/__main__.py -> build/lib.macosx-10.9-universal2-cpython-39/gambaterm
  copying gambaterm/colors.py -> build/lib.macosx-10.9-universal2-cpython-39/gambaterm
  copying gambaterm/py.typed -> build/lib.macosx-10.9-universal2-cpython-39/gambaterm
  running build_ext
  /private/var/folders/fc/j5c56kcn0rj1kx27qbwj8mvw0000gp/T/pip-build-env-kowrg3ox/overlay/lib/python3.9/site-packages/Cython/Compiler/Main.py:381: FutureWarning: Cython directive 'language_level' not set, using '3str' for now (Py3). This has changed from earlier releases! File: /private/var/folders/fc/j5c56kcn0rj1kx27qbwj8mvw0000gp/T/pip-install-jiydfwsf/gambaterm_a9b39a9344ef4a49a377734962d452e5/libgambatte_ext/libgambatte.pyx
    tree = Parsing.p_module(s, pxd, full_module_name)

  Error compiling Cython file:
  ------------------------------------------------------------
  ...
  # distutils: language = c++
  # distutils: libraries = gambatte

  cimport numpy as np
  from libcpp.string cimport string
  from _libgambatte cimport GB as C_GB
  ^
  ------------------------------------------------------------

  libgambatte_ext/libgambatte.pyx:6:0: '_libgambatte.pxd' not found

  Error compiling Cython file:
  ------------------------------------------------------------
  ...
  # distutils: language = c++
  # distutils: libraries = gambatte

  cimport numpy as np
  from libcpp.string cimport string
  from _libgambatte cimport GB as C_GB
  ^
  ------------------------------------------------------------

  libgambatte_ext/libgambatte.pyx:6:0: '_libgambatte/GB.pxd' not found

  Error compiling Cython file:
  ------------------------------------------------------------
  ...
  # distutils: libraries = gambatte

  cimport numpy as np
  from libcpp.string cimport string
  from _libgambatte cimport GB as C_GB
  from _libgambatte cimport GetInput as C_GetInput
  ^
  ------------------------------------------------------------

  libgambatte_ext/libgambatte.pyx:7:0: '_libgambatte/GetInput.pxd' not found

  Error compiling Cython file:
  ------------------------------------------------------------
  ...
  from _libgambatte cimport GB as C_GB
  from _libgambatte cimport GetInput as C_GetInput


  cdef class GB:
      cdef C_GB c_gb
           ^
  ------------------------------------------------------------

  libgambatte_ext/libgambatte.pyx:11:9: 'C_GB' is not a type identifier

  Error compiling Cython file:
  ------------------------------------------------------------
  ...
  from _libgambatte cimport GetInput as C_GetInput


  cdef class GB:
      cdef C_GB c_gb
      cdef C_GetInput c_getinput
           ^
  ------------------------------------------------------------

  libgambatte_ext/libgambatte.pyx:12:9: 'C_GetInput' is not a type identifier

  Error compiling Cython file:
  ------------------------------------------------------------
  ...
          np.ndarray[np.int16_t, ndim=2] audio,
          size_t samples,
      ):
          cdef unsigned int* video_buffer = <unsigned int*> video.data
          cdef unsigned int* audio_buffer = <unsigned int*> audio.data
          result = self.c_gb.runFor(video_buffer, pitch, audio_buffer, samples)
                                    ^
  ------------------------------------------------------------

  libgambatte_ext/libgambatte.pyx:29:34: Cannot convert 'unsigned int *' to Python object

  Error compiling Cython file:
  ------------------------------------------------------------
  ...
          np.ndarray[np.int16_t, ndim=2] audio,
          size_t samples,
      ):
          cdef unsigned int* video_buffer = <unsigned int*> video.data
          cdef unsigned int* audio_buffer = <unsigned int*> audio.data
          result = self.c_gb.runFor(video_buffer, pitch, audio_buffer, samples)
                                                         ^
  ------------------------------------------------------------

  libgambatte_ext/libgambatte.pyx:29:55: Cannot convert 'unsigned int *' to Python object

  Error compiling Cython file:
  ------------------------------------------------------------
  ...
          self,
          np.ndarray[np.uint32_t, ndim=2] video,
          ptrdiff_t pitch,
      ):
          if video is None:
              return self.c_gb.saveState(NULL, 0)
                                         ^
  ------------------------------------------------------------

  libgambatte_ext/libgambatte.pyx:53:39: Cannot convert 'void *' to Python object

  Error compiling Cython file:
  ------------------------------------------------------------
  ...
          ptrdiff_t pitch,
      ):
          if video is None:
              return self.c_gb.saveState(NULL, 0)
          cdef unsigned int* video_buffer = <unsigned int*> video.data
          return self.c_gb.saveState(video_buffer, pitch)
                                     ^
  ------------------------------------------------------------

  libgambatte_ext/libgambatte.pyx:55:35: Cannot convert 'unsigned int *' to Python object
  Compiling libgambatte_ext/libgambatte.pyx because it changed.
  [1/1] Cythonizing libgambatte_ext/libgambatte.pyx
  Traceback (most recent call last):
    File "/Users/tobias.waslowski/projects/personal/gambaterm/venv/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 349, in <module>
      main()
    File "/Users/tobias.waslowski/projects/personal/gambaterm/venv/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 331, in main
      json_out['return_val'] = hook(**hook_input['kwargs'])
    File "/Users/tobias.waslowski/projects/personal/gambaterm/venv/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 248, in build_wheel
      return _build_backend().build_wheel(wheel_directory, config_settings,
    File "/private/var/folders/fc/j5c56kcn0rj1kx27qbwj8mvw0000gp/T/pip-build-env-kowrg3ox/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 415, in build_wheel
      return self._build_with_temp_dir(
    File "/private/var/folders/fc/j5c56kcn0rj1kx27qbwj8mvw0000gp/T/pip-build-env-kowrg3ox/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 397, in _build_with_temp_dir
      self.run_setup()
    File "/private/var/folders/fc/j5c56kcn0rj1kx27qbwj8mvw0000gp/T/pip-build-env-kowrg3ox/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 313, in run_setup
      exec(code, locals())
    File "<string>", line 46, in <module>
    File "/private/var/folders/fc/j5c56kcn0rj1kx27qbwj8mvw0000gp/T/pip-build-env-kowrg3ox/overlay/lib/python3.9/site-packages/setuptools/__init__.py", line 103, in setup
      return distutils.core.setup(**attrs)
    File "/private/var/folders/fc/j5c56kcn0rj1kx27qbwj8mvw0000gp/T/pip-build-env-kowrg3ox/overlay/lib/python3.9/site-packages/setuptools/_distutils/core.py", line 184, in setup
      return run_commands(dist)
    File "/private/var/folders/fc/j5c56kcn0rj1kx27qbwj8mvw0000gp/T/pip-build-env-kowrg3ox/overlay/lib/python3.9/site-packages/setuptools/_distutils/core.py", line 200, in run_commands
      dist.run_commands()
    File "/private/var/folders/fc/j5c56kcn0rj1kx27qbwj8mvw0000gp/T/pip-build-env-kowrg3ox/overlay/lib/python3.9/site-packages/setuptools/_distutils/dist.py", line 970, in run_commands
      self.run_command(cmd)
    File "/private/var/folders/fc/j5c56kcn0rj1kx27qbwj8mvw0000gp/T/pip-build-env-kowrg3ox/overlay/lib/python3.9/site-packages/setuptools/dist.py", line 974, in run_command
      super().run_command(command)
    File "/private/var/folders/fc/j5c56kcn0rj1kx27qbwj8mvw0000gp/T/pip-build-env-kowrg3ox/overlay/lib/python3.9/site-packages/setuptools/_distutils/dist.py", line 989, in run_command
      cmd_obj.run()
    File "/private/var/folders/fc/j5c56kcn0rj1kx27qbwj8mvw0000gp/T/pip-build-env-kowrg3ox/overlay/lib/python3.9/site-packages/setuptools/command/bdist_wheel.py", line 373, in run
      self.run_command("build")
    File "/private/var/folders/fc/j5c56kcn0rj1kx27qbwj8mvw0000gp/T/pip-build-env-kowrg3ox/overlay/lib/python3.9/site-packages/setuptools/_distutils/cmd.py", line 316, in run_command
      self.distribution.run_command(command)
    File "/private/var/folders/fc/j5c56kcn0rj1kx27qbwj8mvw0000gp/T/pip-build-env-kowrg3ox/overlay/lib/python3.9/site-packages/setuptools/dist.py", line 974, in run_command
      super().run_command(command)
    File "/private/var/folders/fc/j5c56kcn0rj1kx27qbwj8mvw0000gp/T/pip-build-env-kowrg3ox/overlay/lib/python3.9/site-packages/setuptools/_distutils/dist.py", line 989, in run_command
      cmd_obj.run()
    File "/private/var/folders/fc/j5c56kcn0rj1kx27qbwj8mvw0000gp/T/pip-build-env-kowrg3ox/overlay/lib/python3.9/site-packages/setuptools/_distutils/command/build.py", line 135, in run
      self.run_command(cmd_name)
    File "/private/var/folders/fc/j5c56kcn0rj1kx27qbwj8mvw0000gp/T/pip-build-env-kowrg3ox/overlay/lib/python3.9/site-packages/setuptools/_distutils/cmd.py", line 316, in run_command
      self.distribution.run_command(command)
    File "/private/var/folders/fc/j5c56kcn0rj1kx27qbwj8mvw0000gp/T/pip-build-env-kowrg3ox/overlay/lib/python3.9/site-packages/setuptools/dist.py", line 974, in run_command
      super().run_command(command)
    File "/private/var/folders/fc/j5c56kcn0rj1kx27qbwj8mvw0000gp/T/pip-build-env-kowrg3ox/overlay/lib/python3.9/site-packages/setuptools/_distutils/dist.py", line 989, in run_command
      cmd_obj.run()
    File "/private/var/folders/fc/j5c56kcn0rj1kx27qbwj8mvw0000gp/T/pip-build-env-kowrg3ox/overlay/lib/python3.9/site-packages/setuptools/command/build_ext.py", line 93, in run
      _build_ext.run(self)
    File "/private/var/folders/fc/j5c56kcn0rj1kx27qbwj8mvw0000gp/T/pip-build-env-kowrg3ox/overlay/lib/python3.9/site-packages/setuptools/_distutils/command/build_ext.py", line 359, in run
      self.build_extensions()
    File "/private/var/folders/fc/j5c56kcn0rj1kx27qbwj8mvw0000gp/T/pip-build-env-kowrg3ox/overlay/lib/python3.9/site-packages/setuptools/_distutils/command/build_ext.py", line 479, in build_extensions
      self._build_extensions_serial()
    File "/private/var/folders/fc/j5c56kcn0rj1kx27qbwj8mvw0000gp/T/pip-build-env-kowrg3ox/overlay/lib/python3.9/site-packages/setuptools/_distutils/command/build_ext.py", line 505, in _build_extensions_serial
      self.build_extension(ext)
    File "/private/var/folders/fc/j5c56kcn0rj1kx27qbwj8mvw0000gp/T/pip-build-env-kowrg3ox/overlay/lib/python3.9/site-packages/setuptools/command/build_ext.py", line 254, in build_extension
      _build_ext.build_extension(self, ext)
    File "/private/var/folders/fc/j5c56kcn0rj1kx27qbwj8mvw0000gp/T/pip-build-env-kowrg3ox/overlay/lib/python3.9/site-packages/Cython/Distutils/build_ext.py", line 130, in build_extension
      new_ext = cythonize(
    File "/private/var/folders/fc/j5c56kcn0rj1kx27qbwj8mvw0000gp/T/pip-build-env-kowrg3ox/overlay/lib/python3.9/site-packages/Cython/Build/Dependencies.py", line 1154, in cythonize
      cythonize_one(*args)
    File "/private/var/folders/fc/j5c56kcn0rj1kx27qbwj8mvw0000gp/T/pip-build-env-kowrg3ox/overlay/lib/python3.9/site-packages/Cython/Build/Dependencies.py", line 1321, in cythonize_one
      raise CompileError(None, pyx_file)
  Cython.Compiler.Errors.CompileError: libgambatte_ext/libgambatte.pyx
  ----------------------------------------
  ERROR: Failed building wheel for gambaterm
Failed to build gambaterm
ERROR: Could not build wheels for gambaterm which use PEP 517 and cannot be installed directly

My versions:

Python 3.9.6
cmake 3.29.6
macOS 14.5

@vxgmichel
Copy link
Owner

vxgmichel commented Jul 2, 2024

Thank you @twaslowski for creating this issue :)

It seems like the source distribution is broken because some files are not included in the source archive:

libgambatte_ext/libgambatte.pyx:6:0: '_libgambatte.pxd' not found

At least the following files are missing:

  • libgambatte_ext/input.h
  • libgambatte_ext/_libgambatte.pxd

I'll try to make a new release with those files incuded.

Still I'm a bit surprised that pip chose to build the project from the source instead of using this wheel:

Any idea of what went wrong?

@vxgmichel
Copy link
Owner

Version 0.12.7 is out 🎉

@twaslowski
Copy link
Author

Wow, that was really fast. Thank you very much!

Still I'm a bit surprised that pip chose to build the project from the source instead of using this wheel:

Any idea of what went wrong?

Yeah, me being dumb. I messed up the Python version with pyenv. When using Python3.9 properly, it does use the wheel. On the bright side though, compiling from source now works as intended all the way up to Python3.12 now!

python3.12 -m pip install gambaterm runs successfully; and python3.12 -m pip show gambaterm shows that it is on version 0.12.7.

@twaslowski
Copy link
Author

twaslowski commented Jul 4, 2024

I found a separate issue running games though, which occurs on either Python version (3.9 and 3.12):

OSError: cannot load library '/Users/tobias.waslowski/.pyenv/versions/3.12.4/lib/python3.12/site-packages/samplerate/_samplerate_data/libsamplerate.dylib': dlopen(/Users/tobias.waslowski/.pyenv/versions/3.12.4/lib/python3.12/site-packages/samplerate/_samplerate_data/libsamplerate.dylib, 0x0002): tried: '/Users/tobias.waslowski/.pyenv/versions/3.12.4/lib/python3.12/site-packages/samplerate/_samplerate_data/libsamplerate.dylib' (mach-o file, 
but is an incompatible architecture (have 'x86_64', need 'arm64e' or 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Users/tobias.waslowski/.pyenv/versions/3.12.4/lib/python3.12/site-packages/samplerate/_samplerate_data/libsamplerate.dylib' (no such file), '/Users/tobias.waslowski/.pyenv/versions/3.12.4/lib/python3.12/site-packages/samplerate/_samplerate_data/libsamplerate.dylib' 
(mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e' or 'arm64'))

Do you happen to know anything about this? I assume it's a downstream issue with either samplerate or libsamplerate; I'm not expecting a fix here, but if you have any guidance on getting this to work on Apple Silicon processors, or any experience with either of those libraries, I'd appreciate it :)

@vxgmichel
Copy link
Owner

vxgmichel commented Jul 4, 2024

On the bright side though, compiling from source now works as intended all the way up to Python3.12 now!

Yey 🎉

Do you happen to know anything about this?

I know I had to pin samplerate to version 0.1.0 due to tuxu/python-samplerate#19.

Maybe try to force version 0.2.1 and see how it goes?

You should also be able to skip to import of samplerate by using the --disable-audio option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants