如何解决python-datamodel安装报错:ValueError: 'datamodel/fields.pyx'无匹配文件
解决python-datamodel安装报错问题
问题场景
执行命令 pip install python-datamodel 时出现编译报错,环境为Windows系统+VSCode,Python版本3.11.1(官方文档标注该包支持Python3.8及以上版本),核心报错信息:
ValueError: 'datamodel/fields.pyx' doesn't match any files
完整报错日志:
Collecting python-datamodel Using cached python-datamodel-0.1.13.tar.gz (290 kB) Installing build dependencies ... done Getting requirements to build wheel ... error error: subprocess-exited-with-error × Getting requirements to build wheel did not run successfully. │ exit code: 1 ╰─> [25 lines of output] Traceback (most recent call last): File "C:\Users\Zheng Yao\AppData\Local\Programs\Python\Python311\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 353, in <module> main() File "C:\Users\Zheng Yao\AppData\Local\Programs\Python\Python311\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 335, in main json_out['return_val'] = hook(**hook_input['kwargs']) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Zheng Yao\AppData\Local\Programs\Python\Python311\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 118, in get_requires_for_build_wheel return hook(config_settings) ^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Zheng Yao\AppData\Local\Temp\pip-build-env-xxrinum0\overlay\Lib\site-packages\setuptools\build_meta.py", line 338, in get_requires_for_build_wheel return self._get_build_requires(config_settings, requirements=['wheel']) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Zheng Yao\AppData\Local\Temp\pip-build-env-xxrinum0\overlay\Lib\site-packages\setuptools\build_meta.py", line 320, in _get_build_requires self.run_setup() File "C:\Users\Zheng Yao\AppData\Local\Temp\pip-build-env-xxrinum0\overlay\Lib\site-packages\setuptools\build_meta.py", line 335, in run_setup exec(code, locals()) File "<string>", line 154, in <module> File "C:\Users\Zheng Yao\AppData\Local\Temp\pip-build-env-xxrinum0\overlay\Lib\site-packages\Cython\Build\Dependencies.py", line 970, in cythonize module_list, module_metadata = create_extension_list( ^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Zheng Yao\AppData\Local\Temp\pip-build-env-xxrinum0\overlay\Lib\site-packages\Cython\Build\Dependencies.py", line 816, in create_extension_list for file in nonempty(sorted(extended_iglob(filepattern)), "'%s' doesn't match any files" % filepattern): File "C:\Users\Zheng Yao\AppData\Local\Temp\pip-build-env-xxrinum0\overlay\Lib\site-packages\Cython\Build\Dependencies.py", line 114, in nonempty raise ValueError(error_msg) ValueError: 'datamodel/fields.pyx' doesn't match any files [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. error: subprocess-exited-with-error
解决方案
方案1:安装预编译wheel包
源码包缺失Cython编译所需的源文件,优先尝试安装预编译的wheel包:
- 先升级pip及相关工具:
pip install --upgrade pip setuptools wheel - 下载对应Python3.11版本的wheel文件(需适配cp311标签),执行本地安装:
pip install python_datamodel-0.1.13-cp311-none-any.whl
方案2:手动修复源码后本地编译
如果找不到对应wheel包,可手动补全缺失文件后编译:
- 下载源码包:
pip download python-datamodel --no-deps - 解压下载的
python-datamodel-0.1.13.tar.gz文件,进入解压目录 - 在解压目录中创建
datamodel文件夹,补全缺失的fields.pyx等Cython源文件 - 执行本地安装:
pip install .
方案3:切换兼容Python版本
由于部分包对最新Python版本的编译支持存在延迟,可临时切换到Python3.9或3.10版本,再执行pip install python-datamodel,大概率能正常完成安装。
内容的提问来源于stack exchange,提问作者zampoan
相关产品推荐
相关产品推荐

