pyyaml: "AttributeError: cython_sources" with Cython 3.0.0a10
When attempting to install PyYAML from sources with Cython 3.0.0a10, e.g. like so:
pip install --pre -v git+https://github.com/yaml/pyyaml.git
the install fails with:
Using pip 21.3.1 from /home/florian/tmp/toxtest/.venv/lib/python3.10/site-packages/pip (python 3.10)
Collecting git+https://github.com/yaml/pyyaml.git
Cloning https://github.com/yaml/pyyaml.git to /tmp/pip-req-build-rdv2sw86
Running command git version
git version 2.34.1
Running command git clone --filter=blob:none -q https://github.com/yaml/pyyaml.git /tmp/pip-req-build-rdv2sw86
Running command git rev-parse HEAD
8cdff2c80573b8be8e8ad28929264a913a63aa33
Resolved https://github.com/yaml/pyyaml.git to commit 8cdff2c80573b8be8e8ad28929264a913a63aa33
Running command /home/florian/tmp/toxtest/.venv/bin/python3 /tmp/pip-standalone-pip-7sp3xayz/__env_pip__.zip/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-az2k859x/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple --pre -- setuptools wheel Cython
Collecting setuptools
Using cached setuptools-60.5.0-py3-none-any.whl (958 kB)
Collecting wheel
Using cached wheel-0.37.1-py2.py3-none-any.whl (35 kB)
Collecting Cython
Using cached Cython-3.0.0a10-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_24_x86_64.whl (2.2 MB)
Installing collected packages: wheel, setuptools, Cython
Successfully installed Cython-3.0.0a10 setuptools-60.5.0 wheel-0.37.1
Installing build dependencies ... done
Running command /home/florian/tmp/toxtest/.venv/bin/python3 /home/florian/tmp/toxtest/.venv/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py get_requires_for_build_wheel /tmp/tmpqirb9t5l
running egg_info
creating lib/PyYAML.egg-info
writing manifest file 'lib/PyYAML.egg-info/SOURCES.txt'
Traceback (most recent call last):
File "/home/florian/tmp/toxtest/.venv/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 363, in <module>
main()
File "/home/florian/tmp/toxtest/.venv/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 345, in main
json_out['return_val'] = hook(**hook_input['kwargs'])
File "/home/florian/tmp/toxtest/.venv/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 130, in get_requires_for_build_wheel
return hook(config_settings)
File "/tmp/pip-build-env-az2k859x/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 162, in get_requires_for_build_wheel
return self._get_build_requires(
File "/tmp/pip-build-env-az2k859x/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 143, in _get_build_requires
self.run_setup()
File "/tmp/pip-build-env-az2k859x/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 158, in run_setup
exec(compile(code, __file__, 'exec'), locals())
File "setup.py", line 288, in <module>
setup(
File "/tmp/pip-build-env-az2k859x/overlay/lib/python3.10/site-packages/setuptools/__init__.py", line 155, in setup
return distutils.core.setup(**attrs)
File "/tmp/pip-build-env-az2k859x/overlay/lib/python3.10/site-packages/setuptools/_distutils/core.py", line 148, in setup
return run_commands(dist)
File "/tmp/pip-build-env-az2k859x/overlay/lib/python3.10/site-packages/setuptools/_distutils/core.py", line 163, in run_commands
dist.run_commands()
File "/tmp/pip-build-env-az2k859x/overlay/lib/python3.10/site-packages/setuptools/_distutils/dist.py", line 967, in run_commands
self.run_command(cmd)
File "/tmp/pip-build-env-az2k859x/overlay/lib/python3.10/site-packages/setuptools/_distutils/dist.py", line 986, in run_command
cmd_obj.run()
File "/tmp/pip-build-env-az2k859x/overlay/lib/python3.10/site-packages/setuptools/command/egg_info.py", line 299, in run
self.find_sources()
File "/tmp/pip-build-env-az2k859x/overlay/lib/python3.10/site-packages/setuptools/command/egg_info.py", line 306, in find_sources
mm.run()
File "/tmp/pip-build-env-az2k859x/overlay/lib/python3.10/site-packages/setuptools/command/egg_info.py", line 541, in run
self.add_defaults()
File "/tmp/pip-build-env-az2k859x/overlay/lib/python3.10/site-packages/setuptools/command/egg_info.py", line 578, in add_defaults
sdist.add_defaults(self)
File "/tmp/pip-build-env-az2k859x/overlay/lib/python3.10/site-packages/setuptools/_distutils/command/sdist.py", line 228, in add_defaults
self._add_defaults_ext()
File "/tmp/pip-build-env-az2k859x/overlay/lib/python3.10/site-packages/setuptools/_distutils/command/sdist.py", line 312, in _add_defaults_ext
self.filelist.extend(build_ext.get_source_files())
File "setup.py", line 204, in get_source_files
self.cython_sources(ext.sources, ext)
File "/tmp/pip-build-env-az2k859x/overlay/lib/python3.10/site-packages/setuptools/_distutils/cmd.py", line 103, in __getattr__
raise AttributeError(attr)
AttributeError: cython_sources
Getting requirements to build wheel ... error
WARNING: Discarding git+https://github.com/yaml/pyyaml.git. Command errored out with exit status 1: /home/florian/tmp/toxtest/.venv/bin/python3 /home/florian/tmp/toxtest/.venv/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py get_requires_for_build_wheel /tmp/tmpqirb9t5l Check the logs for full command output.
ERROR: Command errored out with exit status 1: /home/florian/tmp/toxtest/.venv/bin/python3 /home/florian/tmp/toxtest/.venv/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py get_requires_for_build_wheel /tmp/tmpqirb9t5l Check the logs for full command output.
I’m not sure if this is an intended change in Cython 3, or a bug - but given that “pyyaml setup is still relying on a bunch of ancient custom distutils bits” (#584) I thought I’d report it here first. Please let me know if you think I should rather report it there.
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 94
- Comments: 100 (7 by maintainers)
Links to this issue
- kubetools · PyPI
- django - Build failed with aws ebcli on Python 3.11.4 - Stack Overflow
- Docker-compose no longer building image (AttributeError: cython_sources) - Stack Overflow
- chore(deps): update dependency pyyaml to v6.0.1 (!442) · Merge requests · GlitchTip / GlitchTip Backend · GitLab
- chore(deps): update dependency pyyaml to v6.0.1 (!442) · Merge requests · GlitchTip / GlitchTip Backend · GitLab
Commits related to this issue
- Don't install PyYAML from git for bleeding CI Workaround for https://github.com/yaml/pyyaml/issues/601 — committed to qutebrowser/qutebrowser by The-Compiler 2 years ago
- Don't install PyYAML from git for bleeding CI Workaround for https://github.com/yaml/pyyaml/issues/601 — committed to twigleingrid/qutebrowser by The-Compiler 2 years ago
- Don't install PyYAML from git for bleeding CI Workaround for https://github.com/yaml/pyyaml/issues/601 — committed to crides/qutebrowser by The-Compiler 2 years ago
- Hack installation of PyYAML on pypy Currently PyYAML fails to build with Cython 3.0.0a, thus it fails to install from sdist using `pip install --pre`. See https://github.com/yaml/pyyaml/issues/601 — committed to dairiki/marshmallow_dataclass by dairiki 2 years ago
- Hack installation of PyYAML on pypy Currently PyYAML fails to build with Cython 3.0.0a, thus it fails to install from sdist using `pip install --pre`. See https://github.com/yaml/pyyaml/issues/601 — committed to dairiki/marshmallow_dataclass by dairiki 2 years ago
- Test under Python 3.11, update CI workflow to latest versions of actions (#220) * Test under Python 3.11 * Do not set PYTHONWARNINGS=error during CI pytest That catches, e.g., deprecation warni... — committed to lovasoa/marshmallow_dataclass by dairiki 2 years ago
- Pin Cython for tests, so that PyYAML can build (#1492) See: https://github.com/yaml/pyyaml/issues/601 Signed-off-by: Rick Elrod <rick@elrod.me> — committed to ansible/awx-operator by relrod a year ago
- Pin Cython for tests, so that PyYAML can build (#1492) See: https://github.com/yaml/pyyaml/issues/601 Signed-off-by: Rick Elrod <rick@elrod.me> — committed to relrod/awx-operator by relrod a year ago
- chore(api): pin PyYAML build dependency See https://github.com/yaml/pyyaml/issues/601 — committed to Rotzbua/desec-stack by peterthomassen a year ago
- Fix "make -C Documentation builder-image" Use this workaround until the issue gets fixed: https://github.com/yaml/pyyaml/issues/601#issuecomment-1638509577 Signed-off-by: Michi Mutsuzaki <michi@iso... — committed to cilium/cilium by michi-covalent a year ago
- Pin PyYAML<=5.3 https://github.com/yaml/pyyaml/issues/601#issuecomment-1638555590 — committed to aiidalab/aiidalab-docker-stack by danielhollas a year ago
- fix: relax PyYaml specification to work around 'mach vendor' issue in Gecko I don't understand the details, but somehow the recent Cython 3.0 release broke the ability to build PyYaml. There's curren... — committed to ahal/taskgraph by ahal a year ago
- fix: relax PyYaml specification to work around 'mach vendor' issue in Gecko I don't understand the details, but somehow the recent Cython 3.0 release broke the ability to build PyYaml. There's curren... — committed to taskcluster/taskgraph by ahal a year ago
- Install pyyaml with an available musl wheel to avoid issue with https://github.com/yaml/pyyaml/issues/601 — committed to vertexproject/synapse by vEpiphyte a year ago
- Fix "make -C Documentation builder-image" Use this workaround until the issue gets fixed: https://github.com/yaml/pyyaml/issues/601#issuecomment-1638509577 Signed-off-by: Michi Mutsuzaki <michi@iso... — committed to cilium/cilium by michi-covalent a year ago
- Install pyyaml with an available musl wheel to avoid issue with https://github.com/yaml/pyyaml/issues/601 (#3246) — committed to vertexproject/synapse by vEpiphyte a year ago
- Molecule: Different fix for new Cython The first attempt (#1492) was unfortunately wrong in two ways. We need to pin the dependency in inside the container, not as a molecule dependency. Also it seem... — committed to relrod/awx-operator by relrod a year ago
- Downgraded PyYaml because it broke for alpine. See: https://github.com/yaml/pyyaml/issues/601 — committed to wolfswolke/DeathGarden_API_Rebirth by wolfswolke a year ago
- remove pyyaml constraint to allow >=6.0 the primary motivation for this change is to remove issues with cython >=3.0 see https://github.com/yaml/pyyaml/issues/601 the fideslang update is needed sinc... — committed to ethyca/fides by adamsachs a year ago
- action.yml: Hotfix for https://github.com/yaml/pyyaml/issues/601 — committed to dlmiles/tt-gds-action by dlmiles a year ago
Any update on this, now that Cython 3.0 has been released?
Our workaround for the time being is, in our build process, to install a compatible cython first and then use --no-build-isolation. Eg
if that helps anyone
Is it possible to release a
5.4.2
version with Cpython restricted to “❤️.0.0” ? This should solve some of the immediate problems related to 3rd party libraries pinning down PyYaml to versions lower than 6.0.As with all the mentions, this is breaking our ability to build our production apps.
Is there any chance of getting a release that pins Cython? Failing that does anyone know how to work around this by pinning Cython when using poetry?
Edit: I’ve realized that this is happening for PyYaml 6.0 too
Two workarounds exist:
cython<3
, then install pyyaml without build isolation, then install the rest of your dependencies https://github.com/yaml/pyyaml/issues/601#issuecomment-1660456820cython<3
at build time https://github.com/yaml/pyyaml/issues/601#issuecomment-1661960662Solution
For Solving this on Docker: Include these 2 lines in your Dockerfile
I hope it solves your problem 😃
Try ths: pip install PyYaml==3.10
Ping. Cython 3.0.0 has already reached beta releases, so we need some solution sooner than later.
Totally solved on 6.0.1 for me
For my poetry based projects building in docker I was able to work around this by doing the following in my docker file:
This would help out a ton! Half of my CI builds are still wrecked by third-party dependencies that keep trying to install 5.4.1
Sorry for commenting on someone else but DO NOT USE @yinxs2003 solution without considerations. It will install more than a 10-year-old version. In the meantime, PyYAML has at least one critical vulnerability fixed.
@yinxs2003 If You could at least inform people of the danger of using “older” code it would be great.
For folks relying on aws-cli, pinning
pyyaml<=5.3.1
helped us.NOTE - please read this note from aws-cli maintainers before you use
pyyaml<=5.3.1
:#702 was merged, 6.0.1 released, and this can be closed https://github.com/yaml/pyyaml/pull/702#issuecomment-1639058497
@nitzmahone is there anyway we can get https://github.com/yaml/pyyaml/pull/702 merged and released in 6.x to help stem the current build issues? There unfortunately isn’t a robust way for downstream packages to mitigate this without defining a runtime dependency on Cython for constraint.
This issue affects tensorflow/models object detection api installation and gives the same set of errors.
Downgrading pyyaml to 5.3.1 ( from 6.0.1 ) manually resolves it.
Just building on @pinghedm’s solution. If you happen to have another package that depends on pyyaml 5.x (like awscli). You can install it like this:
Thanks @jwmatthews I will check this , For now I have
pip install “cython<3.0.0” wheel && pip install pyyaml==5.4.1 --no-build-isolation, It seems my build happens fine. I will check if my tests pass
I would dearly love to see https://github.com/yaml/pyyaml/pull/702 get merged and released as 6.0.1, as a workaround to this issue, at least for folks using version 6.0.0
^^above not working for me
Here’s my dockerFile
It’s definitely a regression between Cython 3.0.0a9 and a10; every previous 3.0.0 alpha has been able to build the pyyaml extension fine. This PR (included in a10) swapped out the base class on Cython’s custom
build_ext
distutils command (which pyyaml further subclasses to customize some stuff). I haven’t dug down all the way yet to see if it’s something we should try to address in pyyaml’s customization or if it’s just a bug in the new base class.Thanks for the report- regardless, we’ll want to get this sorted one way or another, so I’ll figure out where the problem is and work with the Cython/setuptools folks if necessary to get it working.
For anyone who’s struggling with the issue @nanonyme mentioned (installing current Cython first and using
--no-build-isolation
to install PyYAML), I’ve found that patching line 85 of the PyYAMLsetup.py
script fromto
before installing works for me with Cython 3.0.7 and PyYAML 6.0.1. It seems that the old
build_ext
was replaced in Cython but still lives inold_build_ext.py
. That’s probably a temporary solution, though, untilold_build_ext
will be removed.Edit: I see that option is discussed (and rejected for long-term use) in https://github.com/cython/cython/issues/4568.
I encountered this error with Pipenv… any help to workaround it is appreciated. Thanks I do not know how to convert the workaround
pip install "cython<3.0.0" wheel && pip install pyyaml==5.4.1 --no-build-isolation
in Pipefile.Thanks @jwmatthews, this works for me
@r-asiebert
The specific issue here is if you’re trying to install PyYAML on a system that doesn’t have a wheel available. Cython is only involved when building from source. Most of the report are on Alpine because there aren’t musl wheels available. If 6.x is working, my guess is you’re using Python 3.10 or 3.11 which didn’t have wheels available in the 5.4.1 release.
This will continue to be an issue until the build dependencies are properly constrained.
adding
pip install wheel
fixed it for us@jimbojd72 I had the same problem and the resolution was to
pip install wheel
before thepip install "Cython<3.0" ...
commandIt’s not necessarily to document workarounds. You can take pip or pypa/build and keep build isolation on. (which is the default) This will install compatible dependencies into virtualenv/venv to produce a wheel. You can then install wheel outside virtualenv/venv. This issue is about fixing compatibility with new Cython.
https://stackoverflow.com/a/77491847/13086128
IMHO, cython should be listed as permanent dependency of pyyaml if installing it might fail when it is missing, otherwise is a source of pain for the users.
Also this translates to other problems down the line because if that dependency is not listed, people would have to create an additional step to pre-install ‘hidden’ dependencies before installing normal ones, as installation order might make it fail otherwise.
I observed this bug not only with latest pyyaml 3.x but also on macos and ubuntu.
At the risk of repeating what has been said a dozen times already, I found this while trying to install
docker-compose
withpipx
. This was my workaround:Thanks!
Thank you. The first approach worked for me
The same for me 🎉 Encountered this issue on 6.0, bumping version to 6.0.1 solved it.
Could we just get a
.post1
out that addresses only this?Our project’s requirements/CI/CD setup is quite complex and it’s grounded until this is addressed.
A version of this that worked with us using
pipenv install
in our CI pipeline:This is breaking all my testing for 3.12, which doesn’t have wheels (they can be uploaded pretty safely now with 3.12.0b4).
You can set
PIP_CONSTRAINTS_FILE
to a file with a constraint on pyyaml that will lock an older version if that helps. Or on Cython, which would help, I think. I’m not sure Poetry will respect it, but most tools use pip which will.Reporting identical issues in an Ubuntu 20.04 container running Python 3.10.1 compiled from source + pip 21.3.
cython compilation error specifically with
pyyaml==5.4.1
, installs fine with latest (6.0) or 5.3.1.Sad morning to discover PEP 518 (
--no-build-isolation
). So much for freezing myrequirements.txt
😕and stop using outdated distutils, as well. Use instead setuptools, or meson.
Well, yes, clearly there is no other long-term solution than making pyyaml support Cython 3.
@JannKleen yes, however, as it appears, some users are installing pyyaml through first installing cython and then using --no-build-isolation. This will bypass the build dependency requirement written into pyproject.toml and reproduce the original problem.
Version 6.0.1 now seems to require Cython < 3.0.0, so the workaround isn’t required anymore I believe.
Hello. pyyaml 3.13, 5.3.1, 5.4.1, 6.0.1 py 2.7, 3.5, 3.8 python setup build
result:
all
This normal?
Same for me
Does anybody solved the issue for python:3.9-slim-bullseye docker image?
It does, at least for me (I cut in the stack trace for brevity):
Is there any way to specify
--no-build-isolation
inside of asetup.cfg
orrequirements.txt
file?this fixed it for me.
@muleyashutosh
Install
gcc
and other required build dependencies before doing the pip install (apk add gcc
etc)I encountered this error when attempting to lock my dependencies with
pipenv
; I was able to fix it in my case by settingjust figured I’d share this in case it helps someone else.
same, this worked for me as well. thanks!
https://stackoverflow.com/questions/77490435/attributeerror-cython-sources/77491847#77491847
That is just a workaround and doesn’t solve the underlying problem which is especially important if you can’t downgrade cython because another project actually requires 3.0
This works if you compile from build file from GoHlke
I downgraded
pyyaml
version:It’s working! For the time being. I think.
For the poetry users, when you run a command like the following in your Dockerfile, just make sure the pyyaml version matches whatever is in your poetry.lock file, otherwise poetry will try to install a new version and you get the same error.
I was able to work around this in Alpine. We’re using Alpine 3.15, but I think the same solution should work: https://github.com/Cray-HPE/cray-product-catalog/pull/263
@Kaelten thanks for the suggestion! That works for me on Poetry 1.5.1!
Anyone using poetry? It seems I only can use 6 version with it.
Does anyone had the same problem?
For some package managers, e.g. Poetry, even defining a Cython runtime dependency doesn’t help because Poetry builds wheels for sdist packages upon installation in a temporary directory that’s isolated from the runtime environment and only includes packages defined in PEP 517’s
build-requires
Building with pyyaml pinned to version 5.3.1 fixed this issue for me
@nitzmahone That’s my bad, I think! The tests failed immediately (try to import
imp
, keeping an eye on https://github.com/cython/cython/issues/5285) but I thought it’d failed to compile too.I’m going to test a bunch of reverse dependencies like pyyaml in Gentoo and unleash it if it works. Apologies for the error!
EDIT: Done!
@mgorny where are you hearing that? Empirically speaking, Cython 0.29.x has been working flawlessly on 3.12- PyYAML extension builds have been passing the full test suite all along through the current Python 3.12.0b1.
(not that I don’t want a better excuse to spend the time shredding PyYAML’s creaky old packaging code to work under Cython3 while still doing everything it needs to do 😆 )
@jmakov the likely short-term fix will be to pin the Cython PEP518 build deps to pre-3.0 Cython in a 6.x release (see #702), but we generally consider the 5.x release branch dead, so hadn’t planned on re-publishing the build change back there. You might want to try and get the Pycaret folks (or whoever’s ultimately pinning PyYAML to
~=5.1
) to update their deps.Cool- we’ve been poking at doing another release, and since we sat on it long enough, setuptools and pip now fully support PEP517/518 config passthru from the CLI, which should make the replacement of the dynamic bits a whole lot easier.
Yep, unfortunately
--pre
seems to affect all deps and build deps as well underpip
.