r9y9/pyopenjtalk

Build compatibility with Cython 3.0

Z-H-Sun opened this issue · 3 comments

Known-Good Solution

With Python==3.10, MSVC==14.3 (VS 2022), and Cython<3.0 (e.g., cython==0.29.35), I was able to successfully build pyopenjtalk on Windows 11 using

  • either pip install pyopenjtalk --no-build-isolation to install v0.3.0,
  • or pip install git+https://github.com/r9y9/pyopenjtalk.git --no-build-isolation to install a nightly build

Symptom

However, with the official release of Cython 3.0 9 hours ago, the build will fail without the --no-build-isolation option (i.e., using the latest Cython by default, rather than the current available version), with the following error message:

...
Error compiling Cython file:
------------------------------------------------------------
...
from openjtalk.mecab cimport Mecab, Mecab_initialize, Mecab_load, Mecab_analysis
^
------------------------------------------------------------

pyopenjtalk\openjtalk.pyx:13:0: 'openjtalk\mecab.pxd' not found
...

FYI, Line 13 is from openjtalk.mecab cimport Mecab, Mecab_initialize, ...

Basically, Cython was unable to include the path <...>/pyopenjtalk/pyopenjtalk and thus unable to find the openjtalk/*.pyx and htsengine/*.pyx submodules.

Possible Workarounds

If I copy the folder pyopenjtalk/pyopenjtalk/openjtalk and pyopenjtalk/pyopenjtalk/htsengine (which contain all the pyx files) to their parent folder (i.e., into pyopenjtalk/openjtalk and pyopenjtalk/htsengine respectively), the build is OK with the latest Cython version. But in doing so, one has to make the corresponding changes and then build locally.

Of course, as I mentioned in the first section, downgrading the cython version and adding the --no-build-isolation option can be another much easier workaround.

I have minimum experience with Cython, so I can't determine whether this is an intended change or just a bug of the latest version of Cython. So I am posting my experience here in the hope of helping other coders who might run into this problem in the future. Ideally, of course, it's best if the author could kindly update the package for Cython 3.0 compatibility or point out this known issue in the README.

I can confirm that this happen to older version of cython as well. (I use Cython 0.29.21 )
I recently made a change to a spaces in huggingface, which trigger spaces to rebuild all requirements, result in above error (which work last week).

Test in newly created Ubuntu jammy on wsl2 as well, result in the same error.

I can confirm that this happen to older version of cython as well. (I use Cython 0.29.21 ) I recently made a change to a spaces in huggingface, which trigger spaces to rebuild all requirements, result in above error (which work last week).

Test in newly created Ubuntu jammy on wsl2 as well, result in the same error.

@Lycoris52 Did you specify --no-build-isolation when calling pip? If not, pip will automatically choose to use the latest version of cython, which has now become 3.0 (to be more specific, since yesterday).

I asked this question because cython 0.29.35 worked for me.

Nevertheless, this behavior is very confusing, and I don't think this is a desirable one.

@Lycoris52 Did you specify --no-build-isolation when calling pip? If not, pip will automatically choose to use the latest version of cython, which has now become 3.0 (to be more specific, since yesterday).

I asked this question because cython 0.29.35 worked for me.

Nevertheless, this behavior is very confusing, and I don't think this is a desirable one.

@Z-H-Sun
Thank you for your advice, I rebuild the huggingface spaces using docker instance seperating cython0.29.35 and pyopenjtalk installation with --no-build-isolation. Everything is now working again.