Repository navigation
Description
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
jnothman commentedon Nov 26, 2018
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.rstfor 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.
jnothman commentedon Nov 26, 2018
That having been said, we're running AppVeyor with Cython 0.27... so maybe this is something we should get our act together on.
anntzer commentedon Nov 26, 2018
Again, my (strictly personal) suggestion is to not include cython-generated files in the sdist, and avoid the whole problem.
amueller commentedon Nov 26, 2018
@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.
rth commentedon Nov 26, 2018
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...
anntzer commentedon Nov 26, 2018
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).
amueller commentedon Nov 26, 2018
@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.
anntzer commentedon Nov 27, 2018
I would guess the solution I linked to above also works with numpy.distutils, but I haven't tried.
mexicarne commentedon Nov 28, 2018
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:
Definitely something should be done to make cython to regenereate this files.
mexicarne commentedon Nov 28, 2018
Nevermind, I found the
build_srctargetrth commentedon Nov 28, 2018
Cython.Build.cythonizehas aforceoption to force cythonization. Enabling it here might be enough.But we should make this easier in any case.
mexicarne commentedon Nov 28, 2018
Sadly that didn't helped, nor running
build_srcbeforebuildandinstallin setup.py.rth commentedon Nov 28, 2018
Interestingly I can't reproduce this using the v0.20.1 git tag, compiled with
Cython==0.23.5and 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,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
.pyxfiles 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,
2 remaining items
Work around scikit-learn/scikit-learn#12671
amueller commentedon Dec 14, 2018
I think for 0.20.2 we just want to make sure we generate the C files with cython 0.29, right?
adrinjalali commentedon Dec 14, 2018
does that mean our CI should also use that cython? I'm still not clear about our cython version dependency.
amueller commentedon Dec 14, 2018
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.
amueller commentedon Dec 14, 2018
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)
jnothman commentedon Dec 17, 2018
adrinjalali commentedon Dec 18, 2018
@jnothman I'm not sure what you mean by "tested" though. Any automated process you have in mind which would test that for us?
rth commentedon Dec 18, 2018
I imagine one that is used in CI.
jnothman commentedon Dec 18, 2018
science/py-scikit-learn: update to 0.20.2
science/py-scikit-learn: update to 0.20.2
science/py-scikit-learn: update to 0.20.2
adrinjalali commentedon Dec 20, 2018
I suppose 0.20.2 release has fixed this. Please comment/reopen if the issue persists.
science/py-scikit-learn: update to 0.20.2