使用pip安装tar.gz文件时出现“没有名为'Cython'的模块”的错误

14

我使用Poetry来构建tar.gz和whl文件,用于我的示例软件包(https://github.com/iamishalkin/cyrtd),然后尝试在pipenv环境中安装软件包。tar.gz安装失败,下面是部分日志:

$ poetry build
...
$ pip install dist/cyrtd-0.1.0.tar.gz
Processing c:\work2\cyrtd\dist\cyrtd-0.1.0.tar.gz
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
Requirement already satisfied: cython<0.30.0,>=0.29.13 in c:\users\ivan.mishalkin\.virtualenvs\cyrtd-tpdvsw8x\lib\site-packages (from cyrtd==0.1.0) (0.29.15)
Building wheels for collected packages: cyrtd
  Building wheel for cyrtd (PEP 517) ... error
  ERROR: Command errored out with exit status 1:
...
from Cython.Build import cythonize
  ModuleNotFoundError: No module named 'Cython'  
  ----------------------------------------
  ERROR: Failed building wheel for dxpyfeed
Failed to build dxpyfeed
ERROR: Could not build wheels for dxpyfeed which use PEP 517 and cannot be installed directly
Cython已安装并可以从虚拟解释器中调用。即使在日志中写入了Cython的要求已满足,但有一件奇怪的事情 - 几个月前一切都正常工作。我尝试了conda venv,升级了Cython和Poetry,但都没有帮助。还尝试了与Cython相关的一个弱关联的解决方法,链接为:setup_requires with Cython? 仍然没有运气。 更新:我在这里找到了一个不太干净的解决方法:https://luminousmen.com/post/resolve-cython-and-numpy-dependencies 想法是添加:
from setuptools import dist
dist.Distribution().fetch_build_eggs(['cython'])

在导入Cython.Build之前

执行后我得到以下日志:

$ pip install dist/cyrtd-0.1.0.tar.gz
Processing c:\work2\cyrtd\dist\cyrtd-0.1.0.tar.gz
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
Requirement already satisfied: cython<0.30.0,>=0.29.13 in c:\users\ivan.mishalkin\.virtualenvs\cyrtd-tpdvsw8x\lib\site-packages (from cyrtd==0.1.0) (0.29.15)
Building wheels for collected packages: cyrtd
  Building wheel for cyrtd (PEP 517) ... done
  Created wheel for cyrtd: filename=cyrtd-0.1.0-cp37-cp37m-win_amd64.whl size=33062 sha256=370a90657759d3183f3c11ebbdf1d23c3ca857d41dd45a86386ba33a6baf9a07
  Stored in directory: c:\users\ivan.mishalkin\appdata\local\pip\cache\wheels\45\d1\6b\52daecf1cc5234ca4d9e9e49b2f195e7adb83941424116432e
Successfully built cyrtd
Installing collected packages: cyrtd
  Attempting uninstall: cyrtd
    Found existing installation: cyrtd 0.1.0
    Uninstalling cyrtd-0.1.0:
      Successfully uninstalled cyrtd-0.1.0
Successfully installed cyrtd-0.1.0

仍在寻找更好的解决方案

更新2: 主要文件内容: build.py:

from setuptools import Extension
from Cython.Build import cythonize

cyfuncs_ext = Extension(name='cyrtd.cymod.cyfuncs',
                        sources=['cyrtd/cymod/cyfuncs.pyx']
                        )

EXTENSIONS = [
    cyfuncs_ext
]

def build(setup_kwargs):
    setup_kwargs.update({
        'ext_modules': cythonize(EXTENSIONS, language_level=3),
        'zip_safe': False,
        'setup_requires':['setuptools>=18.0', 'cython']
    })

1
build.py 脚本是否已设置为 [tool.poetry].build 中的值,或者您如何绑定它? - Arne
1
@Arne 是的,当然它绑定在 pyproject.toml 文件中。问题的仓库包含所有的代码。 - Ivan Mishalkin
啊,我没看到你链接了你的代码库。这对你来说是一个合适的解决方案吗?还是你还在寻找更好的东西?如果它足够好,考虑将其发布为一个自包含的答案。 - Arne
@Arne,一段时间以前一切都正常,没有这样的解决方法,所以我很有信心会有更好的解决方案。问题是我不知道出了什么问题和在哪里寻找错误。 - Ivan Mishalkin
1个回答

2
pyproject.toml的构建系统部分添加cython对我很有帮助。 pyproject.toml:
...
[build-system]
requires = ["poetry>=0.12", "cython"]
...

令我惊讶的是,这对我也起作用了。 - tharen

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接