Ubuntu环境下pip构建wxPython Wheel失败求助
wxPython安装失败问题排查
问题描述
我尝试在Python 3.10、3.12以及3.13版本中安装wxPython,但均以几乎相同的错误失败,我已安装了尽可能多的必要依赖包,请问有人知道问题出在哪里吗?
错误日志
2025-04-24T15:50:35,367 make[1]: *** [Makefile:28693: coredll_sound_sdl.o] Error 1 2025-04-24T15:50:35,367 make[1]: *** Waiting for unfinished jobs.... 2025-04-24T15:50:40,070 make[1]: Leaving directory '/tmp/pip-install-sb8y98_e/wxpython_07aa987c368f479ba95852e8f4be3929/build/wxbld/gtk3' 2025-04-24T15:50:40,071 Error building 2025-04-24T15:50:40,071 ERROR: failed building wxWidgets 2025-04-24T15:50:40,073 Traceback (most recent call last): 2025-04-24T15:50:40,073 File "/tmp/pip-install-sb8y98_e/wxpython_07aa987c368f479ba95852e8f4be3929/build.py", line 1607, in cmd_build_wx 2025-04-24T15:50:40,073 wxbuild.main(wxDir(), build_options) 2025-04-24T15:50:40,073 ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^ 2025-04-24T15:50:40,073 File "/tmp/pip-install-sb8y98_e/wxpython_07aa987c368f479ba95852e8f4be3929/buildtools/build_wxwidgets.py", line 505, in main 2025-04-24T15:50:40,073 exitIfError(wxBuilder.build(dir=buildDir, options=args), "Error building") 2025-04-24T15:50:40,074 ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2025-04-24T15:50:40,074 File "/tmp/pip-install-sb8y98_e/wxpython_07aa987c368f479ba95852e8f4be3929/buildtools/build_wxwidgets.py", line 70, in exitIfError 2025-04-24T15:50:40,074 raise builder.BuildError(msg) 2025-04-24T15:50:40,074 buildtools.builder.BuildError: Error building 2025-04-24T15:50:40,074 Finished command: build_wx (7m52.940s) 2025-04-24T15:50:40,074 Finished command: build (7m52.940s) 2025-04-24T15:50:40,130 WARNING: Building this way assumes that all generated files have been 2025-04-24T15:50:40,130 generated already. If that is not the case then use build.py directly 2025-04-24T15:50:40,130 to generate the source and perform the build stage. You can use 2025-04-24T15:50:40,130 --skip-build with the bdist_* or install commands to avoid this 2025-04-24T15:50:40,130 message and the wxWidgets and Phoenix build steps in the future. 2025-04-24T15:50:40,130 "/home/cnobile/.virtualenvs/nc3.13/bin/python" -u build.py build 2025-04-24T15:50:40,131 Command '"/home/cnobile/.virtualenvs/nc3.13/bin/python" -u build.py build' failed with exit code 1. 2025-04-24T15:50:40,197 ERROR: Building wheel for wxPython (pyproject.toml) exited with 1 2025-04-24T15:50:40,202 [bold magenta]full command[/]: [blue]/home/cnobile/.virtualenvs/nc3.13/bin/python /home/cnobile/.virtualenvs/nc3.13/lib/python3.13/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py build_wheel /tmp/tmp3i6rdxss[/] 2025-04-24T15:50:40,202 [bold magenta]cwd[/]: /tmp/pip-install-sb8y98_e/wxpython_07aa987c368f479ba95852e8f4be3929 2025-04-24T15:50:40,203 ERROR: Failed building wheel for wxPython 2025-04-24T15:50:40,203 Failed to build wxPython 2025-04-24T15:50:40,266 Remote version of pip: 25.0.1 2025-04-24T15:50:40,266 Local version of pip: 25.0.1 2025-04-24T15:50:40,268 Was pip installed by pip? True 2025-04-24T15:50:40,269 ERROR: Failed to build installable wheels for some pyproject.toml based projects (wxPython) 2025-04-24T15:50:40,269 Exception information: 2025-04-24T15:50:40,269 Traceback (most recent call last): 2025-04-24T15:50:40,269 File "/home/cnobile/.virtualenvs/nc3.13/lib/python3.13/site-packages/pip/_internal/cli/base_command.py", line 106, in _run_wrapper 2025-04-24T15:50:40,269 status = _inner_run() 2025-04-24T15:50:40,269 File "/home/cnobile/.virtualenvs/nc3.13/lib/python3.13/site-packages/pip/_internal/cli/base_command.py", line 97, in _inner_run 2025-04-24T15:50:40,269 return self.run(options, args) 2025-04-24T15:50:40,269 ~~~~~~~~^^^^^^^^^^^^^^^ 2025-04-24T15:50:40,269 File "/home/cnobile/.virtualenvs/nc3.13/lib/python3.13/site-packages/pip/_internal/cli/req_command.py", line 67, in wrapper 2025-04-24T15:50:40,269 return func(self, options, args) 2025-04-24T15:50:40,269 File "/home/cnobile/.virtualenvs/nc3.13/lib/python3.13/site-packages/pip/_internal/commands/install.py", line 435, in run 2025-04-24T15:50:40,269 raise InstallationError( 2025-04-24T15:50:40,269 ...<4 lines>... 2025-04-24T15:50:40,269 ) 2025-04-24T15:50:40,269 pip._internal.exceptions.InstallationError: Failed to build installable wheels for some pyproject.toml based projects (wxPython) 2025-04-24T15:50:40,270 Removed build tracker: '/tmp/pip-build-tracker-2k4mpfgl'
解决方案
从错误日志看,核心问题是编译wxWidgets时SDL音频模块(coredll_sound_sdl.o)失败,可尝试以下几种解决方法:
安装SDL开发依赖库:
- Debian/Ubuntu系:执行
sudo apt-get install libsdl2-dev libsdl2-mixer-dev - RHEL/CentOS系:执行
sudo dnf install SDL2-devel SDL2_mixer-devel - macOS:执行
brew install sdl2 sdl2_mixer
- Debian/Ubuntu系:执行
使用预编译wheel包安装:
避免源码编译,直接安装预编译版本,执行命令:pip install wxPython --only-binary :all:若需要指定版本,可添加版本号,如
pip install wxPython==4.2.1 --only-binary :all:禁用SDL音频支持:
若不需要音频功能,可在编译时禁用SDL,设置环境变量后再安装:export WX_CONFIGURE_OPTIONS="--disable-sound" pip install wxPython检查编译器版本:
确保系统安装的gcc/g++版本在8.0及以上,wxPython对编译器版本有最低要求,版本过低会导致编译失败。
内容的提问来源于stack exchange,提问作者cnobile
相关产品推荐
相关产品推荐

