Python安装discord.py时multidict编译失败问题求助
问题描述
我当前使用Python 3.12版本,使用pip安装各类软件包时频繁遇到相同错误,尝试降级至3.8、3.9版本或使用最新版本均无法解决。已执行pip install pyproject-toml,但安装discord.py时仍出现如下报错:
Defaulting to user installation because normal site-packages is not writeable Collecting discord.py Using cached discord.py-2.3.2-py3-none-any.whl.metadata (4.9 kB) Collecting aiohttp<4,>=3.7.4 (from discord.py) Using cached aiohttp-3.9.1-cp312-cp312-win_amd64.whl.metadata (7.6 kB) Requirement already satisfied: attrs>=17.3.0 in c:\users\hoang\appdata\local\packages\pythonsoftwarefoundation.python.3.12_qbz5n2kfra8p0\localcache\local-packages\python312\site-packages (from aiohttp<4,>=3.7.4->discord.py) (23.1.0) Collecting multidict<7.0,>=4.5 (from aiohttp<4,>=3.7.4->discord.py) Using cached multidict-6.0.4.tar.gz (51 kB) Installing build dependencies ... done Getting requirements to build wheel ... done Installing backend dependencies ... done Preparing metadata (pyproject.toml) ... done Collecting yarl<2.0,>=1.0 (from aiohttp<4,>=3.7.4->discord.py) Using cached yarl-1.9.4-cp312-cp312-win_amd64.whl.metadata (32 kB) Collecting frozenlist>=1.1.1 (from aiohttp<4,>=3.7.4->discord.py) Using cached frozenlist-1.4.1-cp312-cp312-win_amd64.whl.metadata (12 kB) Collecting aiosignal>=1.1.2 (from aiohttp<4,>=3.7.4->discord.py) Using cached aiosignal-1.3.1-py3-none-any.whl (7.6 kB) Requirement already satisfied: idna>=2.0 in c:\users\hoang\appdata\local\packages\pythonsoftwarefoundation.python.3.12_qbz5n2kfra8p0\localcache\local-packages\python312\site-packages (from yarl<2.0,>=1.0->aiohttp<4,>=3.7.4->discord.py) (3.6) Using cached discord.py-2.3.2-py3-none-any.whl (1.1 MB) Using cached aiohttp-3.9.1-cp312-cp312-win_amd64.whl (362 kB) Using cached frozenlist-1.4.1-cp312-cp312-win_amd64.whl (50 kB) Using cached yarl-1.9.4-cp312-cp312-win_amd64.whl (76 kB) Building wheels for collected packages: multidict Building wheel for multidict (pyproject.toml) ... error error: subprocess-exited-with-error × Building wheel for multidict (pyproject.toml) did not run successfully. │ exit code: 1 ╰─> [74 lines of output] ********************* * Accelerated build * ********************* running bdist_wheel running build running build_py creating build creating build\lib.win-amd64-cpython-312 creating build\lib.win-amd64-cpython-312\multidict copying multidict\_abc.py -> build\lib.win-amd64-cpython-312\multidict copying multidict\_compat.py -> build\lib.win-amd64-cpython-312\multidict copying multidict\_multidict_base.py -> build\lib.win-amd64-cpython-312\multidict copying multidict\_multidict_py.py -> build\lib.win-amd64-cpython-312\multidict copying multidict\__init__.py -> build\lib.win-amd64-cpython-312\multidict running egg_info writing multidict.egg-info\PKG-INFO writing dependency_links to multidict.egg-info\dependency_links.txt writing top-level names to multidict.egg-info\top_level.txt reading manifest file 'multidict.egg-info\SOURCES.txt' reading manifest template 'MANIFEST.in' warning: no previously-included files matching '*.pyc' found anywhere in distribution warning: no previously-included files found matching 'multidict\_multidict.html' warning: no previously-included files found matching 'multidict\*.so' warning: no previously-included files found matching 'multidict\*.pyd' warning: no previously-included files found matching 'multidict\*.pyd' no previously-included directories found matching 'docs\_build' adding license file 'LICENSE' writing manifest file 'multidict.egg-info\SOURCES.txt' C:\Users\hoang\AppData\Local\Temp\pip-build-env-0k190i2x\overlay\Lib\site-packages\setuptools\command\build_py.py:207: _Warning: Package 'multidict._multilib' is absent from the `packages` configuration. !! ******************************************************************************** ############################ # Package would be ignored # ############################ Python recognizes 'multidict._multilib' as an importable package[^1], but it is absent from setuptools' `packages` configuration. This leads to an ambiguous overall configuration. If you want to distribute this package, please make sure that 'multidict._multilib' is explicitly added to the `packages` configuration field. Alternatively, you can also rely on setuptools' discovery methods (for example by using `find_namespace_packages(...)`/`find_namespace:` instead of `find_packages(...)`/`find:`). You can read more about "package discovery" on setuptools documentation page: - https://setuptools.pypa.io/en/latest/userguide/package_discovery.html If you don't want 'multidict._multilib' to be distributed and are already explicitly excluding 'multidict._multilib' via `find_namespace_packages(...)/find_namespace` or `find_packages(...)/find`, you can try to use `exclude_package_data`, or `include-package-data=False` in combination with a more fine grained `package-data` configuration. You can read more about "package data files" on setuptools documentation page: - https://setuptools.pypa.io/en/latest/userguide/datafiles.html [^1]: For Python, any directory (with suitable naming) can be imported, even if it does not contain any `.py` files. On the other hand, currently there is no concept of package data directory, all directories are treated like packages. ******************************************************************************** !! check.warn(importable) copying multidict\__init__.pyi -> build\lib.win-amd64-cpython-312\multidict copying multidict\py.typed -> build\lib.win-amd64-cpython-312\multidict running build_ext building 'multidict._multidict' extension error: [WinError 2] The system cannot find the file specified [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for multidict Failed to build multidict ERROR: Could not build wheels for multidict, which is required to install pyproject.toml-based projects
解决办法
- 安装Microsoft Visual C++ Build Tools:Windows环境下编译Python的C扩展依赖该工具,安装时勾选「C++ build tools」以及对应的Windows SDK组件,安装完成后重启终端再尝试安装。
- 强制使用预编译轮子:先执行
pip install --only-binary :all: multidict安装预编译好的multidict包,之后再运行pip install discord.py。 - 升级pip到最新版本:执行
python -m pip install --upgrade pip,新版pip对预编译轮子的检索和支持更完善,可能自动匹配到适配Python版本的预编译包。 - 使用虚拟环境规避权限问题:报错提示普通site-packages目录无写入权限,可创建虚拟环境隔离依赖,执行
python -m venv myenv创建,再通过myenv\Scripts\activate激活环境,之后在虚拟环境内安装discord.py。
内容的提问来源于stack exchange,提问作者Hoàng Nhism
相关产品推荐
相关产品推荐

