[Python] Error `ModuleNotFoundError: No module named 'Cython'` encountered when using `uv...

Discussão em 'Python' iniciado por Stack, Abril 12, 2025.

  1. Stack

    Stack Membro Participativo

    I am using uv as my package manager in building a python package of my own. Actually I switched from the typical setuptools to uv because I found that uv is fast and great. However when I run uv build just as I have used python -m build in using setuptools, I encountered an error saying ModuleNotFoundError: No module named 'Cython'.

    Below is my project's pyproject.toml file, in which numpy is one of the dependencies. I don't know whether it is numpy that causes the problem. I have tried uv tool install cython and uv add --dev cython, but neither solved the problem.

    [project]
    name = "fantazia"
    version = "0.0.1"
    authors = [{ name = "F. X. P.", email = "vanleefxp@gmail.com" }]
    description = "A package for math-based music theory computation."
    readme = "README.md"
    requires-python = ">=3.12"
    classifiers = [
    "Programming Language :: Python :: 3",
    "Operating System :: OS Independent",
    "License :: OSI Approved :: MIT License",
    ]
    keywords = ["music"]
    dependencies = [
    "bidict>=0.23.1",
    "numpy>=2.2.4",
    "pyrsistent>=0.20.0",
    "scikit-learn>=1.6.1",
    "scipy>=1.15.2",
    "sortedcontainers>=2.4.0",
    ]

    [project.urls]
    Homepage = "https://github.com/vanleefxp/fantazia"
    Issues = "https://github.com/vanleefxp/fantazia/issues"

    [project.optional-dependencies]
    m21 = ["music21>=9.3.0"]

    [dependency-groups]
    dev = [
    "cython>=3.0.12",
    ]


    And below is the full error message:

    Building source distribution...
    Traceback (most recent call last):
    File "<string>", line 14, in <module>
    requires = get_requires_for_build({})
    File "D:\AppData\uv\cache\builds-v0\.tmpl3mxVT\Lib\site-packages\setuptools\build_meta.py", line 337, in get_requires_for_build_sdist
    return self._get_build_requires(config_settings, requirements=[])
    ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "D:\AppData\uv\cache\builds-v0\.tmpl3mxVT\Lib\site-packages\setuptools\build_meta.py", line 304, in _get_build_requires
    self.run_setup()
    ~~~~~~~~~~~~~~^^
    File "D:\AppData\uv\cache\builds-v0\.tmpl3mxVT\Lib\site-packages\setuptools\build_meta.py", line 522, in run_setup
    super().run_setup(setup_script=setup_script)
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "D:\AppData\uv\cache\builds-v0\.tmpl3mxVT\Lib\site-packages\setuptools\build_meta.py", line 320, in run_setup
    exec(code, locals())
    ~~~~^^^^^^^^^^^^^^^^
    File "<string>", line 2, in <module>
    ModuleNotFoundError: No module named 'Cython'
    × Failed to build `D:\New Homeland\Programming\Python\Fantazia`
    ├─▶ The build backend returned an error
    ╰─▶ Call to `setuptools.build_meta:__legacy__.build_sdist` failed (exit code: 1)
    hint: This usually indicates a problem with the package or the build environment.

    Continue reading...

Compartilhe esta Página