You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

安装wxPython时attrdict已安装却提示找不到的问题求助

已安装attrdict却无法安装wxPython 4.2.0?

系统详情

  • 设备:Raspberry Pi Model 4B - 4GB
  • 操作系统:Debian 11 (Bullseye)
  • 目标wxPython版本:PyPI上的4.2.0
  • Python版本:源码编译的3.11.3

问题描述

在虚拟环境中安装wxPython 4.2.0时,明明已安装attrdict依赖,却提示找不到该模块。相关命令执行及报错信息如下:

(.venv) user@raspberrypi:~/Documents $ python --version
Python 3.11.3

(.venv) user@raspberrypi:~/Documents $ python -m pip freeze
attrdict==2.0.1
attrdict3==2.0.2
dbus-fast==1.86.0
pytz==2023.3
six==1.16.0
tzdata==2023.3

(.venv) user@raspberrypi:~/Documents $ python -m pip install wxPython
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting wxPython
  Using cached wxPython-4.2.0.tar.gz (71.0 MB)
  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
  ╰─> [23 lines of output]
      Traceback (most recent call last):
        File "/home/user/Documents/.venv/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
          main()
        File "/home/user/Documents/.venv/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/home/user/Documents/.venv/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 118, in get_requires_for_build_wheel
          return hook(config_settings)
                 ^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-fs9i9itq/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 341, in get_requires_for_build_wheel
          return self._get_build_requires(config_settings, requirements=['wheel'])
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-fs9i9itq/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 323, in _get_build_requires
          self.run_setup()
        File "/tmp/pip-build-env-fs9i9itq/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 488, in run_setup
          self).run_setup(setup_script=setup_script)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-fs9i9itq/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 338, in run_setup
          exec(code, locals())
        File "<string>", line 27, in <module>
        File "/tmp/pip-install-6s5ym1hn/wxpython_0afd12e3eb4741b4854a998e85194d91/buildtools/config.py", line 30, in <module>
          from attrdict import AttrDict
      ModuleNotFoundError: No module named 'attrdict'
      [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.

(.venv) user@raspberrypi:~/Documents $

原因

pip构建wheel包时默认会创建隔离的临时构建环境,该环境不会继承当前虚拟环境已安装的第三方包。因此即便你在虚拟环境中安装了attrdict,wxPython构建时的临时环境里仍缺少这个依赖,导致报错。

解决方法

方法1:跳过构建环境隔离

让pip直接使用当前虚拟环境的依赖构建wxPython,执行命令:

pip install wxPython --no-build-isolation

方法2:安装预编译包(推荐,避免编译耗时)

树莓派编译wxPython耗时极长,piwheels提供了针对树莓派的预编译wxPython包,直接安装可跳过构建步骤:

pip install wxPython --only-binary :all:

你的pip配置已包含piwheels源,该命令会自动拉取对应预编译包。

内容的提问来源于stack exchange,提问作者stackoverflowing321

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 14:23:14