【问题标题】:No module named 'Cython' with pip installation of tar.gz没有使用 tar.gz 的 pip 安装名为“Cython”的模块
【发布时间】:2020-05-30 05:39:36
【问题描述】:

我使用 Poetry 为我的示例包 (https://github.com/iamishalkin/cyrtd) 构建 tar.gz 和 whl 文件,然后尝试在 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 和诗歌,没有任何帮助。 还尝试了来自setup_requires with Cython? 的弱相关解决方法 - 仍然没有运气

UPD:我在这里找到了一些肮脏的解决方法: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

仍在寻找更好的解决方案

UPD2: 主要文件内容: 构建.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']
    })

【问题讨论】:

  • build.py脚本设置为[tool.poetry].build中的值,还是怎么绑定?
  • @Arne 是的,当然它绑定在pyproject.toml 文件中。来自问题的回购包含所有代码
  • 啊,我没有看到你链接了你的仓库。这是适合您的解决方案,还是您仍在寻找更好的解决方案?如果它足够好,请考虑将其作为独立答案发布。
  • @Arne 前段时间没有这种解决方法一切正常,所以我相信有更好的解决方案。问题是我不知道发生了什么变化以及在哪里搜索错误

标签: python cython pipenv python-poetry


【解决方案1】:

pyproject.toml 的构建系统部分添加 cython 帮助了我

pyproject.toml:

...
[build-system]
requires = ["poetry>=0.12", "cython"]
...

【讨论】:

  • 令我惊讶的是,这也为我解决了问题
猜你喜欢
  • 2022-07-30
  • 2017-04-10
  • 1970-01-01
  • 1970-01-01
  • 2018-05-24
  • 2019-11-07
  • 2017-03-18
  • 2015-10-24
  • 2016-10-26
相关资源
最近更新 更多