Windows11下pip安装pysha3失败:无法构建wheel求助
问题
Windows 11系统,已安装Windows C++构建工具,执行pip install pysha3时出现ERROR: Failed building wheel for pysha3错误,编译阶段提示fatal error C1083: Cannot open include file: 'pystrhex.h': No such file or directory,无法完成安装。
完整安装日志:
PS C:\Users\Alexis> pip3 install pysha3 Collecting pysha3 Using cached pysha3-1.0.2.tar.gz (829 kB) Preparing metadata (setup.py) ... done Building wheels for collected packages: pysha3 Building wheel for pysha3 (setup.py) ... error error: subprocess-exited-with-error × python setup.py bdist_wheel did not run successfully. │ exit code: 1 ╰─> [16 lines of output] running bdist_wheel running build running build_py creating build creating build\lib.win-amd64-cpython-311 copying sha3.py -> build\lib.win-amd64-cpython-311 running build_ext building '_pysha3' extension creating build\temp.win-amd64-cpython-311 creating build\temp.win-amd64-cpython-311\Release creating build\temp.win-amd64-cpython-311\Release\Modules creating build\temp.win-amd64-cpython-311\Release\Modules\_sha3 "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.34.31933\bin\HostX86\x64\cl.exe" /c /nologo /O2 /W3 /GL /DNDEBUG /MD -DPY_WITH_KECCAK=1 -IC:\Python311\include -IC:\Python311\Include "-IC:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.34.31933\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\VS\include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\um" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\shared" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\winrt" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\cppwinrt" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um" /TcModules/_sha3/sha3module.c /Fobuild\temp.win-amd64-cpython-311\Release\Modules\_sha3\sha3module.obj sha3module.c C:\Users\Alexis\AppData\Local\Temp\pip-install-78ji94vk\pysha3_9e9c90f2f01445aeb1ab3ed6a6c14e42\Modules\_sha3\backport.inc(78): fatal error C1083: Cannot open include file: 'pystrhex.h': No such file or directory error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\VC\\Tools\\MSVC\\14.34.31933\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2 [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for pysha3 Running setup.py clean for pysha3 Failed to build pysha3 Installing collected packages: pysha3 Running setup.py install for pysha3 ... error error: subprocess-exited-with-error × Running setup.py install for pysha3 did not run successfully. │ exit code: 1 ╰─> [18 lines of output] running install C:\Python311\Lib\site-packages\setuptools\command\install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools. warnings.warn( running build running build_py creating build creating build\lib.win-amd64-cpython-311 copying sha3.py -> build\lib.win-amd64-cpython-311 running build_ext building '_pysha3' extension creating build\temp.win-amd64-cpython-311 creating build\temp.win-amd64-cpython-311\Release creating build\temp.win-amd64-cpython-311\Release\Modules creating build\temp.win-amd64-cpython-311\Release\Modules\_sha3 "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.34.31933\bin\HostX86\x64\cl.exe" /c /nologo /O2 /W3 /GL /DNDEBUG /MD -DPY_WITH_KECCAK=1 -IC:\Python311\include -IC:\Python311\Include "-IC:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.34.31933\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\VS\include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\um" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\shared" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\winrt" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\cppwinrt" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um" /TcModules/_sha3/sha3module.c /Fobuild\temp.win-amd64-cpython-311\Release\Modules\_sha3\sha3module.obj sha3module.c C:\Users\Alexis\AppData\Local\Temp\pip-install-78ji94vk\pysha3_9e9c90f2f01445aeb1ab3ed6a6c14e42\Modules\_sha3\backport.inc(78): fatal error C1083: Cannot open include file: 'pystrhex.h': No such file or directory error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\VC\\Tools\\MSVC\\14.34.31933\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2 [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. error: legacy-install-failure × Encountered error while trying to install package. ╰─> pysha3 note: This is an issue with the package mentioned above, not pip. hint: See above for output from the failure.
解决方案
方案1:安装预编译二进制包(推荐)
pysha3官方版本未适配高版本Python(如你使用的Python3.11),可尝试直接安装预编译wheel包:
- 执行命令强制使用二进制包:
pip install pysha3 --only-binary :all: - 若上述命令失败,手动下载对应版本的wheel文件,执行本地安装:
pip install path\to\pysha3-1.0.2-cp311-cp311-win_amd64.whl
方案2:修改源码适配高版本Python
手动修改临时安装包的代码,解决头文件缺失问题:
- 执行
pip install pysha3触发下载,报错后找到临时目录(日志中的C:\Users\Alexis\AppData\Local\Temp\pip-install-78ji94vk\pysha3_9e9c90f2f01445aeb1ab3ed6a6c14e42\) - 打开
Modules/_sha3/backport.inc文件,将第78行的#include "pystrhex.h"替换为:#if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 10 #include "bytes_methods.h" #else #include "pystrhex.h" #endif - 进入临时目录,执行
python setup.py install完成安装
方案3:使用标准库替代
Python 3.6+的hashlib标准库已内置SHA-3算法,无需安装pysha3:
- 直接在代码中调用:
import hashlib # 计算SHA3-256哈希 hash_result = hashlib.sha3_256(b"your_input_data").hexdigest() print(hash_result) - 若代码依赖pysha3的API格式,可做简单兼容封装:
import hashlib class sha3: @staticmethod def sha3_256(data): return hashlib.sha3_256(data).digest() @staticmethod def sha3_512(data): return hashlib.sha3_512(data).digest()
内容的提问来源于stack exchange,提问作者Alex
相关产品推荐
相关产品推荐

