Error Compiling Cython

2,095 views
Skip to first unread message

Neeraj Chinnu

unread,
Aug 14, 2023, 5:17:52 PM8/14/23
to cython-users
Collecting numpy==1.18.4 (from -r requirements.txt (line 1))
  Downloading numpy-1.18.4.zip (5.4 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 5.4/5.4 MB 41.3 MB/s eta 0:00:00
  Installing build dependencies: started
  Installing build dependencies: finished with status 'done'
  Getting requirements to build wheel: started
  Getting requirements to build wheel: finished with status 'done'
  Preparing metadata (pyproject.toml): started
  Preparing metadata (pyproject.toml): finished with status 'error'
  error: subprocess-exited-with-error
   
  × Preparing metadata (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [55 lines of output]
      Running from numpy source directory.
      <string>:461: UserWarning: Unrecognized setuptools command, proceeding with generating Cython sources and expanding templates
      /tmp/pip-install-oiadjahi/numpy_29861cc28ff2409883f182c28e524f9c/tools/cythonize.py:75: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
        required_version = LooseVersion('0.29.14')
      /tmp/pip-install-oiadjahi/numpy_29861cc28ff2409883f182c28e524f9c/tools/cythonize.py:77: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
        if LooseVersion(cython_version) < required_version:
      warning: /tmp/pip-install-oiadjahi/numpy_29861cc28ff2409883f182c28e524f9c/numpy/__init__.pxd:17:0: The 'DEF' statement is deprecated and will be removed in a future Cython version. Consider using global variables, constants, and in-place literals instead. See https://github.com/cython/cython/issues/4310
       
      Error compiling Cython file:
      ------------------------------------------------------------
      ...
              for i in range(1, RK_STATE_LEN):
                  self.rng_state.key[i] = val[i]
              self.rng_state.pos = i
       
              self._bitgen.state = &self.rng_state
              self._bitgen.next_uint64 = &mt19937_uint64
                                         ^
      ------------------------------------------------------------
       
      _mt19937.pyx:138:35: Cannot assign type 'uint64_t (*)(void *) except? -1 nogil' to 'uint64_t (*)(void *) noexcept nogil'
      Processing numpy/random/_bounded_integers.pxd.in
      Processing numpy/random/_mt19937.pyx
      Traceback (most recent call last):
        File "/tmp/pip-install-oiadjahi/numpy_29861cc28ff2409883f182c28e524f9c/tools/cythonize.py", line 238, in <module>
          main()
        File "/tmp/pip-install-oiadjahi/numpy_29861cc28ff2409883f182c28e524f9c/tools/cythonize.py", line 234, in main
          find_process_files(root_dir)
        File "/tmp/pip-install-oiadjahi/numpy_29861cc28ff2409883f182c28e524f9c/tools/cythonize.py", line 225, in find_process_files
          process(root_dir, fromfile, tofile, function, hash_db)
        File "/tmp/pip-install-oiadjahi/numpy_29861cc28ff2409883f182c28e524f9c/tools/cythonize.py", line 191, in process
          processor_function(fromfile, tofile)
        File "/tmp/pip-install-oiadjahi/numpy_29861cc28ff2409883f182c28e524f9c/tools/cythonize.py", line 80, in process_pyx
          subprocess.check_call(
        File "/usr/lib/python3.10/subprocess.py", line 369, in check_call
          raise CalledProcessError(retcode, cmd)
      subprocess.CalledProcessError: Command '['/usr/bin/python3', '-m', 'cython', '-3', '--fast-fail', '-o', '_mt19937.c', '_mt19937.pyx']' returned non-zero exit status 1.
      Cythonizing sources
      Traceback (most recent call last):
        File "/usr/local/lib/python3.10/dist-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
          main()
        File "/usr/local/lib/python3.10/dist-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
        File "/usr/local/lib/python3.10/dist-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 149, in prepare_metadata_for_build_wheel
          return hook(metadata_directory, config_settings)
        File "/tmp/pip-build-env-9un7z2ah/overlay/local/lib/python3.10/dist-packages/setuptools/build_meta.py", line 380, in prepare_metadata_for_build_wheel
          self.run_setup()
        File "/tmp/pip-build-env-9un7z2ah/overlay/local/lib/python3.10/dist-packages/setuptools/build_meta.py", line 487, in run_setup
          super(_BuildMetaLegacyBackend,
        File "/tmp/pip-build-env-9un7z2ah/overlay/local/lib/python3.10/dist-packages/setuptools/build_meta.py", line 338, in run_setup
          exec(code, locals())
        File "<string>", line 488, in <module>
        File "<string>", line 469, in setup_package
        File "<string>", line 275, in generate_cython
      RuntimeError: Running cythonize failed!
      [end of output]
   
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed
 
× Encountered error while generating package metadata.
╰─> See above for output. 

da-woods

unread,
Aug 15, 2023, 2:46:18 AM8/15/23
to cython...@googlegroups.com
Cython 3 made some backwards-incompatible changes to function types. cdef functions can now raise exceptions by default and this is making the function pointers incompatible.

It looks like you're using a pretty outdated version of Numpy. 1.18.4 came out over 3 years ago.  I believe more recent Numpy is compatible with Cython 3. However if you really need to use 1.18.4 then I suggest you pin Cython to one of the 0.29.x releases.

Possibly 0.29.14, which it looks like it was trying to use, but was asking for in an outdated way so was ignored.
--

---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cython-users/c1e4db3b-54a2-4f3a-b4b1-383acd868cb3n%40googlegroups.com.


Neeraj Chinnu

unread,
Aug 16, 2023, 3:48:09 AM8/16/23
to cython...@googlegroups.com
I have got the same error while using 0.29.20 and now I tried 0.29.14 and still getting the same error!

da-woods

unread,
Aug 16, 2023, 1:33:14 PM8/16/23
to cython...@googlegroups.com
If you're getting exactly the same error then you almost certainly aren't using the version you think you are.

Both

> The 'DEF' statement is deprecated and will be removed in a future Cython version.
and the pointer incompatibility really indicate that you're using Cython 3.

What's quite likely is that Numpy is setting up a temporary environment to build itself and is installing it's own version of Cython. I don't know how you restrict that easily.
Reply all
Reply to author
Forward
0 new messages