pip安装时出现fatal error C1083: 无法打开包括文件: “xxx.h”: No such file or directory-从根源解决
具体为:
pybullet安装时出现fatal error C1083: 无法打开包括文件: “string.h”: No such file or directory
此方法具有通用性。
报错原文
-----
CloneTreeCreator.cpp
D:\Program_Professional\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.38.33130\include\cstring(11): fatal error C1083: 无法打开包括文件: “string.h”: No such file or directory
error: command 'D:\\Program_Professional\\Microsoft Visual Studio\\2022\\BuildTools\\VC\\Tools\\MSVC\\14.38.33130\\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 pybullet
Running setup.py clean for pybullet
Failed to build pybullet
ERROR: Could not build wheels for pybullet, which is required to install pyproject.toml-based projects
网上看了很多回答,都没有能够解决问题。
失败尝试1:Window10 SDK问题
我之前就装过VS了,环境都是满足要求的,也试过同时安装Window10 SDK和Window11 SDK,我的尝试没有什么作用。
失败尝试2:Window10 SDK的路径问题
之前pip安装老是报错io.h找不到,当时就在系统变量和用户变量中添加了路径path,但是在这个问题中不起作用。
此外,添加路径到path对报错似乎没有作用,报错的路径还是D:\Program_Professional\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.38.33130\include\cstring(11): fatal error C1083
实际上,string.h在\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.38\include\ucrt里面也有,但是依旧报找不到文件。
失败尝试3:粘贴文件到目录
我把ucrt里面的所有头文件都复制到了\BuildTools\VC\Tools\MSVC\14.38.33130\include\里面,但是又报错找不到windows.h,于是放弃这种修补方法。
成功尝试1:使用conda安装
参考:https://anaconda.org/conda-forge/pybullet
conda install -c conda-forge pybullet
(tensorflow-gpu-v1) C:\Users\24762\Downloads\bullet3-master\bullet3-master>conda install -c conda-forge pybullet
Collecting package metadata (current_repodata.json): done
Solving environment: unsuccessful initial attempt using frozen solve. Retrying with flexible solve.
Solving environment: unsuccessful attempt using repodata from current_repodata.json, retrying with next repodata source.
Collecting package metadata (repodata.json): done
Solving environment: done
==> WARNING: A newer version of conda exists. <==
current version: 23.7.4
latest version: 23.11.0
Please update conda by running
$ conda update -n base -c defaults conda
Or to minimize the number of packages updated during conda update use
conda install conda=23.11.0
## Package Plan ##
environment location: D:\Program_Professional\Anaconda3\envs\tensorflow-gpu-v1
added / updated specs:
- pybullet
The following packages will be downloaded:
package | build
---------------------------|-----------------
bullet-cpp-3.21 | hcc40339_3 20.6 MB conda-forge
ca-certificates-2023.11.17 | h56e8100_0 151 KB conda-forge
certifi-2023.11.17 | pyhd8ed1ab_0 155 KB conda-forge
pybullet-3.21 | py38hcc40339_3 63.0 MB conda-forge
python_abi-3.8 | 2_cp38 4 KB conda-forge
------------------------------------------------------------
Total: 83.8 MB
The following NEW packages will be INSTALLED:
bullet-cpp conda-forge/win-64::bullet-cpp-3.21-hcc40339_3
pybullet conda-forge/win-64::pybullet-3.21-py38hcc40339_3
python_abi conda-forge/win-64::python_abi-3.8-2_cp38
The following packages will be SUPERSEDED by a higher-priority channel:
ca-certificates anaconda/pkgs/main::ca-certificates-2~ --> conda-forge::ca-certificates-2023.11.17-h56e8100_0
certifi anaconda/pkgs/main/win-64::certifi-20~ --> conda-forge/noarch::certifi-2023.11.17-pyhd8ed1ab_0
Proceed ([y]/n)? y
Downloading and Extracting Packages
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
安装成功了
成功尝试2:手动配置环境变量-从根源解决
这种方法能够从根源解决fatal error C1083: 无法打开包括文件: “xxx.h”: No such file or directory的问题。当然需要首先安装好Window10 SDK,不然可能找不到下面的这些目录(推荐使用Visual Studio Installer安装,安装我之前截图的配置,当然我是window11系统因此用的是Window11 SDK)。
之前的环境变量都是在系统变量中的path中添加,实际上应该在INCLUDE(我电脑中没有自动生成,需要手动创建这个系统变量)中添加,如下所示:
此外,还需要在系统变量的LIB环境下添加(没有现成的也要手动创建,依据编译器的位数选择x86还是x64),有童鞋问为什么加那么多,因为有不同的报错,我自己尝试的时候就是报错一个就添加一个来着:
添加环境变量后一定要重启电脑,再次运行pip命令,如果出现LNK1158: 无法运行“rc.exe” 就参考下面文章解决:
【问题解决】LINK : fatal error LNK1158: 无法运行“rc.exe”