Skip to content

Building from 0.20.1 source distribution on Py3.7 fails because it includes C files generated with old Cython #12671

Closed

Description

@anntzer

Description

Building from 0.20.1 source distribution on Py3.7 fails because it includes C files generated with old Cython.

Steps/Code to Reproduce

In a clean Py3.7 venv, install numpy, scipy, and cython (e.g. 1.15.4, 1.1.0, and 0.29.1, i.e. latest as of now), then

$ pip install --no-binary=:all: scikit-learn
<elided>
    sklearn/cluster/_hierarchical.cpp:24789:22: error: ‘PyThreadState’ {aka ‘struct _ts’} has no member named ‘exc_traceback’; did you mean ‘curexc_traceback’?
         tmp_tb = tstate->exc_traceback;
                          ^~~~~~~~~~~~~
                          curexc_traceback
    sklearn/cluster/_hierarchical.cpp:24790:13: error: ‘PyThreadState’ {aka ‘struct _ts’} has no member named ‘exc_type’; did you mean ‘curexc_type’?
         tstate->exc_type = *type;
                 ^~~~~~~~
                 curexc_type
    sklearn/cluster/_hierarchical.cpp:24791:13: error: ‘PyThreadState’ {aka ‘struct _ts’} has no member named ‘exc_value’; did you mean ‘curexc_value’?
         tstate->exc_value = *value;
                 ^~~~~~~~~
                 curexc_value
    sklearn/cluster/_hierarchical.cpp:24792:13: error: ‘PyThreadState’ {aka ‘struct _ts’} has no member named ‘exc_traceback’; did you mean ‘curexc_traceback’?
         tstate->exc_traceback = *tb;
                 ^~~~~~~~~~~~~
                 curexc_traceback
    error: Command "g++ -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -march=x86-64 -mtune=generic -O3 -pipe -fstack-protector-strong -fno-plt -flto=4 -fuse-linker-plugin -ffat-lto-objects -flto-partition=none -g -march=x86-64 -mtune=generic -O3 -pipe -fstack-protector-strong -fno-plt -march=x86-64 -mtune=generic -O3 -pipe -fstack-protector-strong -fno-plt -fPIC -I/tmp/testenv/lib/python3.7/site-packages/numpy/core/include -I/tmp/testenv/lib/python3.7/site-packages/numpy/core/include -I/tmp/testenv/include -I/usr/include/python3.7m -c sklearn/cluster/_hierarchical.cpp -o build/temp.linux-x86_64-3.7/sklearn/cluster/_hierarchical.o -MMD -MF build/temp.linux-x86_64-3.7/sklearn/cluster/_hierarchical.o.d" failed with exit status 1
    
    ----------------------------------------
Command "/tmp/testenv/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-auq3meb_/scikit-learn/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-lfcer_r1/install-record.txt --single-version-externally-managed --compile --install-headers /tmp/testenv/include/site/python3.7/scikit-learn" failed with error code 1 in /tmp/pip-install-auq3meb_/scikit-learn/

Essentially, this is due to the sdist on PyPI (scikit-learn-0.20.1.tar.gz) containing C-files generated by Cython 0.23.5, which are incompatible with Py3.7.

I would suggest not including the C files in the sdist: if an user is knowledgeable enough to compile scikit-learn themselves (and thus went through the bother of setting up a compilation system, etc.) then hopefully they should be able to install Cython themselves too (or you can declare Cython as a setup_requires, up to you).
Or at least please regenerate these files using the latest version of Cython (but I would consider that a more brittle option).

Expected Results

scikit-learn is installed.

Actual Results

scikit-learn fails to install.

Versions

scikit-learn is not installed, so heh :)
(But Py3.7/Linux and cython 0.29.1 (in the venv).)

Activity

  1. jnothman commented on Nov 26, 2018

    @jnothman
    Member

    Hmmm. This might have been my fault. We should definitely have released it with Cython 0.28. I must have compiled the sdist in an outdated environment. This is not great, and is another thing to make sure we update in maintainers.rst for when release newbies like me try to get involved in releases. :\

    I'm not sure what our options are other than release 0.20.2 as a fix to the source distribution (the wheels should be fine). Sorry to all for bungling that.

  2. jnothman commented on Nov 26, 2018

    @jnothman
    Member

    That having been said, we're running AppVeyor with Cython 0.27... so maybe this is something we should get our act together on.

  3. added this to the 0.20.2 milestone on Nov 26, 2018
  4. anntzer commented on Nov 26, 2018

    @anntzer
    ContributorAuthor

    Again, my (strictly personal) suggestion is to not include cython-generated files in the sdist, and avoid the whole problem.

  5. amueller commented on Nov 26, 2018

    @amueller
    Member

    @anntzer I think that would probably open a new can of worms. Cython makes backward-incompatible changes frequently, so if you're using newer cython it'll break on old versions.

  6. rth commented on Nov 26, 2018

    @rth
    Member

    I also run into a similar issue recently with scipy when trying to build an older scipy on Py37 which came with C files generated by an older Cython. Had to use it from a git tag on Github instead.

    In general though not Cythonizing .tar.gz on PyPi means that Cython needs to be an explicit dependency, that moreover cannot be handled with the usual setuptools mechanism. I also think it would create at least as much trouble as it would solve...

  7. anntzer commented on Nov 26, 2018

    @anntzer
    ContributorAuthor

    In general though not Cythonizing .tar.gz on PyPi means that Cython needs to be an explicit dependency, that moreover cannot be handled with the usual setuptools mechanism. I also think it would create at least as much trouble as it would solve...

    It's really not that hard to make setuptools cooperate, see e.g. https://www.ocf.berkeley.edu/~antonyl/code-recipes.html#setup-time-dependencies-in-setup-py (and then you can even pin a version of Cython as setup_requires if you want).

  8. amueller commented on Nov 26, 2018

    @amueller
    Member

    @anntzer it might be that the tooling improved since we tried last time. We're using numpy distutils though, I'm not sure how nicely this place with that.

    I'd be happy to revisit that if the setup.py is not too complex. We traditionally were also somewhat averse to dependencies, but I don't think there's very good reasons for that tbh.

  9. anntzer commented on Nov 27, 2018

    @anntzer
    ContributorAuthor

    I would guess the solution I linked to above also works with numpy.distutils, but I haven't tried.

  10. mexicarne commented on Nov 28, 2018

    @mexicarne

    So how to manually regenerate c/cpp files? For a temporarty solution I'm tweaking a FreeBSD port of scikit-learn, removed all the c/cpp (keeping pyx files alone) from the distribution and added cython as a build dependency, but now it fails with:

    error: Command "c++ -DNDEBUG -O2 -pipe -fstack-protector -fno-strict-aliasing -fPIC -I/usr/local/lib/python3.7/site-packages/numpy/core/include -c src/libsvm/libsvm_template.cpp -o build/temp.freebsd-13.0-CURRENT-amd64-3.7/src/libsvm/libsvm_template.o -MMD -MF build/temp.freebsd-13.0-CURRENT-amd64-3.7/src/libsvm/libsvm_template.o.d" failed with exit status 1
    c++: error: no such file or directory: 'src/libsvm/libsvm_template.cpp'
    c++: error: no input files
    c++: error: no such file or directory: 'src/libsvm/libsvm_template.cpp'
    c++: error: no input files
    

    Definitely something should be done to make cython to regenereate this files.

  11. mexicarne commented on Nov 28, 2018

    @mexicarne

    Nevermind, I found the build_src target

  12. rth commented on Nov 28, 2018

    @rth
    Member

    Cython.Build.cythonize has a force option to force cythonization. Enabling it here might be enough.

    But we should make this easier in any case.

  13. mexicarne commented on Nov 28, 2018

    @mexicarne

    Cython.Build.cythonize has a force option to force cythonization. Enabling it here might be enough.

    Sadly that didn't helped, nor running build_src before build and install in setup.py.

  14. rth commented on Nov 28, 2018

    @rth
    Member

    Interestingly I can't reproduce this using the v0.20.1 git tag, compiled with Cython==0.23.5 and Python 3.5, then trying to install scikit-learn in a new Py3.7 environment (from the same source) with latest Cython 0.29.1. When I do that, the cythonization is re-triggered automatically with the following messages,

    Compiling sklearn/cluster/_dbscan_inner.pyx because it depends on /home/rth/.miniconda3/envs/sklearn-test-env/lib/python3.7/site-packages/Cython/Includes/libcpp/vector.pxd.
    Compiling sklearn/cluster/_hierarchical.pyx because it depends on /home/rth/.miniconda3/envs/sklearn-test-env/lib/python3.7/site-packages/Cython/Includes/numpy/__init__.pxd.
    Compiling sklearn/cluster/_k_means_elkan.pyx because it depends on /home/rth/.miniconda3/envs/sklearn-test-env/lib/python3.7/site-packages/Cython/Includes/numpy/__init__.pxd.
    Compiling sklearn/cluster/_k_means.pyx because it depends on /home/rth/.miniconda3/envs/sklearn-test-env/lib/python3.7/site-packages/Cython/Includes/numpy/__init__.pxd.
    Compiling sklearn/datasets/_svmlight_format.pyx because it depends on /home/rth/.miniconda3/envs/sklearn-test-env/lib/python3.7/site-packages/Cython/Includes/numpy/__init__.pxd.
    [...]
     [ 1/37] Cythonizing sklearn/cluster/_dbscan_inner.pyx
     [ 2/37] Cythonizing sklearn/cluster/_hierarchical.pyx
    

    Same thing happens with Cython 0.28.

    Now if one creates a sdist in the old environement, and tries to install it in the new one it does fail.

    I'm not sure what's the fundamental difference between these case. Is it because we are not including the source .pyx files in the sdist? Or is there something the setup that prevent it from Cythinizing?

    As a temporary workaround I would just suggest to use the git tag from Github,

    pip install https://github.com/scikit-learn/scikit-learn/archive/0.20.1.tar.gz
    
  15. 2 remaining items

  16. amueller commented on Dec 14, 2018

    @amueller
    Member

    I think for 0.20.2 we just want to make sure we generate the C files with cython 0.29, right?

  17. adrinjalali commented on Dec 14, 2018

    @adrinjalali
    Member

    does that mean our CI should also use that cython? I'm still not clear about our cython version dependency.

  18. amueller commented on Dec 14, 2018

    @amueller
    Member

    I think it's less about "our" dependency than Python 3.7 and gcc and operating systems having Cython dependencies. We build with pretty old cython probably, but gcc might not compile it and some OSs might not run it.

  19. amueller commented on Dec 14, 2018

    @amueller
    Member

    I don't think there's a reason to not always use the newest stable cython (and we make sure we work with the current dev version even)

  20. jnothman commented on Dec 17, 2018

    @jnothman
    Member
  21. adrinjalali commented on Dec 18, 2018

    @adrinjalali
    Member

    @jnothman I'm not sure what you mean by "tested" though. Any automated process you have in mind which would test that for us?

  22. rth commented on Dec 18, 2018

    @rth
    Member

    I'm not sure what you mean by "tested" though

    I imagine one that is used in CI.

  23. jnothman commented on Dec 18, 2018

    @jnothman
    Member
  24. adrinjalali commented on Dec 20, 2018

    @adrinjalali
    Member

    I suppose 0.20.2 release has fixed this. Please comment/reopen if the issue persists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions