pip安装fontconfig报错:exec调用缺少括号,求替代安装方法
通过pip安装fontconfig失败,求替代安装方式
我尝试用pip安装fontconfig包,但遇到了如下报错,请问有没有其他可行的安装方法?
Collecting fontconfig Downloading fontconfig-0.1.zip (121 kB) ---------------------------------------- 122.0/122.0 kB 70.8 kB/s eta 0:00:00 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 ╰─> [22 lines of output] Traceback (most recent call last): File "...\AppData\Local\Programs\Python\Python311\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 353, in <module> main() File "...\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 "...\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 "...\Local\Temp\pip-build-env-gh6zzwr6\overlay\Lib\site-packages\setuptools\build_meta.py", line 325, in get_requires_for_build_wheel return self._get_build_requires(config_settings, requirements=['wheel']) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "...\Local\Temp\pip-build-env-gh6zzwr6\overlay\Lib\site-packages\setuptools\build_meta.py", line 295, in _get_build_requires self.run_setup() File "...\Local\Temp\pip-build-env-gh6zzwr6\overlay\Lib\site-packages\setuptools\build_meta.py", line 487, in run_setup super().run_setup(setup_script=setup_script) File "...\Local\Temp\pip-build-env-gh6zzwr6\overlay\Lib\site-packages\setuptools\build_meta.py", line 311, in run_setup exec(code, locals()) File "<string>", line 9 exec line in glb ^^^^^^^^^^^^^^^^ SyntaxError: Missing parentheses in call to 'exec'. Did you mean exec(...)? [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. error: subprocess-exited-with-error × Getting requirements to build wheel did not run successfully. │ exit code: 1 ╰─> See above for output. note: This error originates from a subprocess, and is likely not a problem with pip.
报错原因
你安装的PyPI上的fontconfig包(版本0.1)是基于Python2开发的,不兼容当前使用的Python3.11,导致编译时出现语法错误。
可行的替代安装方式
安装Python3兼容的替代包
使用python-fontconfig,这是适配Python3的fontconfig绑定,执行命令:pip install python-fontconfig先装系统级fontconfig,再配Python绑定
- 安装系统层面的fontconfig库:
- Windows:通过第三方软件包管理器(如Chocolatey)安装,执行
choco install fontconfig - macOS:用Homebrew安装,执行
brew install fontconfig - Linux:用系统包管理器安装,比如Ubuntu/Debian执行
sudo apt-get install fontconfig libfontconfig1-dev,CentOS/RHEL执行sudo yum install fontconfig fontconfig-devel
- Windows:通过第三方软件包管理器(如Chocolatey)安装,执行
- 安装完成后,再安装
python-fontconfig即可。
- 安装系统层面的fontconfig库:
用conda安装(适用于Anaconda/Miniconda环境)
conda仓库提供适配Python3的fontconfig包,执行命令:conda install -c conda-forge fontconfig
内容的提问来源于stack exchange,提问作者mostafa a
相关产品推荐
相关产品推荐

