pip安装时出现fatal error C1083: 无法打开包括文件: “xxx.h”: No such file or directory-从根源解决

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”

  • 16
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

怡步晓心l

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值