我使用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']
})
build.py
脚本是否已设置为[tool.poetry].build
中的值,或者您如何绑定它? - Arnepyproject.toml
文件中。问题的仓库包含所有的代码。 - Ivan Mishalkin