Python3.9.25环境下安装TensorFlow Federated遇numpy元数据生成错误
Python 3.9.25环境下TensorFlow Federated安装报错解决
问题重现
在Python 3.9.25环境中执行以下安装步骤后,TensorFlow Federated安装失败:
pip install sklearn pip install pandas pip install matplotlib pip install tensorflow pip uninstall --yes tensorboard tb-nightly pip install --quiet --upgrade tensorflow-federated
对应的错误信息:
C:\Users\query1>pip install --quiet --upgrade tensorflow-federated error: subprocess-exited-with-error × Preparing metadata (pyproject.toml) 执行失败。 │ 退出码: 1 ╰─> [22行输出] Running from numpy source directory. <string>:461: UserWarning: Unrecognized setuptools command, proceeding with generating Cython sources and expanding templates Traceback (most recent call last): File "C:\Users\query1\AppData\Local\anaconda3\envs\tff_clean\lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 389, in <module> main() File "C:\Users\query1\AppData\Local\anaconda3\envs\tff_clean\lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 373, in main json_out["return_val"] = hook(**hook_input["kwargs"]) File "C:\Users\query1\AppData\Local\anaconda3\envs\tff_clean\lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 175, in prepare_metadata_for_build_wheel return hook(metadata_directory, config_settings) File "C:\Users\query1\AppData\Local\Temp\pip-build-env-8q__vk7_\overlay\Lib\site-packages\setuptools\build_meta.py", line 374, in prepare_metadata_for_build_wheel self.run_setup() File "C:\Users\query1\AppData\Local\Temp\pip-build-env-8q__vk7_\overlay\Lib\site-packages\setuptools\build_meta.py", line 512, in run_setup super().run_setup(setup_script=setup_script) File "C:\Users\query1\AppData\Local\Temp\pip-build-env-8q__vk7_\overlay\Lib\site-packages\setuptools\build_meta.py", line 317, in run_setup exec(code, locals()) File "<string>", line 488, in <module> File "<string>", line 465, in setup_package File "C:\Users\query1\AppData\Local\Temp\pip-install-l_pjlicm\numpy_d9a5cf74943b41ff9203502af2fd8242\numpy\distutils\__init__.py", line 26, in <module> from . import ccompiler File "C:\Users\query1\AppData\Local\Temp\pip-install-l_pjlicm\numpy_d9a5cf74943b41ff9203502af2fd8242\numpy\distutils\ccompiler.py", line 111, in <module> replace_method(CCompiler, 'find_executables', CCompiler_find_executables) NameError: name 'CCompiler' is not defined [输出结束] note: 该错误源自子进程,大概率与pip无关。 error: metadata-generation-failed × 生成包元数据时出错。 ╰─> numpy note: 此问题与上述包有关,与pip无关。 hint: 详情见上文。
错误原因
安装过程中pip自动拉取的numpy版本与Python 3.9.25、当前setuptools版本不兼容。新版本numpy已弃用distutils模块,导致编译时出现CCompiler未定义的错误。
解决步骤
- 先安装Python 3.9兼容的numpy稳定版本:
pip install numpy==1.24.3
- 重新执行TensorFlow Federated的安装命令:
pip install --upgrade tensorflow-federated
内容的提问来源于stack exchange,提问作者mostafa Mohamed
相关产品推荐
相关产品推荐

