Contents

pyyaml AttributeError: cython_sources

0

The Issue

The problem was first reported on the PyYAML GitHub repository, under the issue titled AttributeError: ‘CythonSources’ with Cython 3.0.0a10. Users reported that when trying to install PyYAML from sources with Cython 3.0.0a10, the installation failed and threw an AttributeError: ‘CythonSources’.

This issue was widely discussed, and several solutions were proposed by the community. In this blog post, we will go over these proposed solutions to help you navigate this compatibility issue.

Possible Solutions

Here are the solutions proposed by the community:

Downgrade PyYAML

Some users reported that downgrading PyYAML to version 5.3.1 resolved the issue. This can be done using pip: pip install pyyaml==5.3.1.

Limit the Cython version

Another solution proposed was to limit the Cython version to less than 3.0.0. This can be done using pip: pip install "cython<3.0.0". This solution might be helpful if your project can work with an older version of Cython.

Upgrade PyYAML

Upgrading PyYAML to version 6.0 may resolve this issue. This can be done using pip: pip install pyyaml==6.0. This might be a viable solution if your project can work with the latest version of PyYAML.

Specific versioning for poetry users

For users using poetry, it may work to set the PyYAML version to whatever is in the poetry.lock file. i.e.

poetry run pip install cython<3.0 pyyaml==5.4.1 --no-build-isolation

Avoid passing --pre to pip

Avoiding the use of the --pre option in pip. The --pre option in pip globally allows pre-releases to be considered for installation, so it affects the package you asked for as well as its entire dependency tree and any build requirements pip installs.

AWSCLI users

Some developers installing awscli also have encountered this error. Pinning PyYAML to version 5.3.1 may help.

References