Python 无法打开包含文件:';io.h';:没有这样的文件或目录

Python 无法打开包含文件:';io.h';:没有这样的文件或目录,python,cython,Python,Cython,我试图用Cython编译一个简单的.pyx文件 print("hello") 这是我的setup.py: from distutils.core import setup from Cython.Build import cythonize setup( ext_modules = cythonize("hello.pyx") ) 然后我运行命令 python setup.py build_ext --inplace 错误如下所示。我努力在谷歌上搜索,但没有发现任何有用的东西 有

我试图用Cython编译一个简单的.pyx文件

print("hello")
这是我的setup.py:

from distutils.core import setup
from Cython.Build import cythonize

setup(
    ext_modules = cythonize("hello.pyx")
)
然后我运行命令

python setup.py build_ext --inplace
错误如下所示。我努力在谷歌上搜索,但没有发现任何有用的东西

有人能帮我解决这个错误吗


我有Anaconda3 4.1.1,Python 3.5,安装了Visual Studio Express 2015。

如果有人发现此线程,并且正在寻找比重新安装VS和/或Anaconda更快的解决方案,我可以通过定义指向io.h位置的环境变量INCLUDE来克服此错误-允许VS编译器定位标头

在我的设置中,使用VS2015,更改为使用通用CRT意味着io.h的位置是
C:\ProgramFiles(x86)\Windows Kits\10\Include\\ucrt

对于不同的版本/环境,io.h的位置可能不同

微软不再努力让控制台开发步骤变得明显。VisualStudio长期以来一直使用一些批处理文件来建立环境变量。当在VS2015/2017中选择C++ CLI开发选项时,添加到开始菜单中的一个或多个快捷键来执行这些批处理文件。 对于VS 2017,各种批处理文件都调用:

C:\Program Files (x86)\Microsoft Visual Studio\Shared\14.0\VC\vcvarsall.bat
具有特定参数

与其设置系统或用户环境变量,不如调用特定的批处理文件来满足构建需求

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat


Python/Ruby/etc需要记住的一点是,为了安装软件包,脚本通常需要将执行shell提升为管理员角色。如果在非管理员shell中执行批处理文件,并且包安装需要提升,那么它将生成一个没有环境变量的子shell。因此,在调用包管理器或脚本之前,您应该在管理员shell中运行批处理文件。

我偶然发现了相同的问题-配置与您的非常相似(唯一的区别是:VS 2015 Pro)。几周后,我终于找到了一个适合我的解决方案

有两个问题。问题1-您需要使用“开发者命令提示符”-有时在“开始”菜单中有这样一个程序,然后您只需使用它

(顺便说一句,对于其他人:Python 3.5需要VS2015,而不是任何其他版本。社区版可以)

如果没有,则可以使用以下代码段(在命令行中):

甚至:

where cl >nul 2>nul || "%VS140COMNTOOLS%vsvars32.bat"
(我将其放在批处理文件中以运行构建环境)

(如果您没有
%VS140COMNTOOLS%
变量,那么您可能只是安装了VS,需要重新启动,以便新的环境变量可见)

现在您将得到错误:

c:\program files\anaconda3\include\pyconfig.h(68): fatal error C1083: Cannot open include file: 'io.h': No such file or directory
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\cl.exe' failed with exit status 2
LINK : fatal error LNK1104: cannot open file 'ucrt.lib'
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\link.exe' failed with exit status 1104
(如编辑后的答案)

因此,现在运行:

set INCLUDE=C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt
好的,现在您将得到错误:

c:\program files\anaconda3\include\pyconfig.h(68): fatal error C1083: Cannot open include file: 'io.h': No such file or directory
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\cl.exe' failed with exit status 2
LINK : fatal error LNK1104: cannot open file 'ucrt.lib'
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\link.exe' failed with exit status 1104
现在怎么办?您需要添加库目录:

set LIB=C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10240.0\um\x64;C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10240.0\ucrt\x64
这次没有错误:

> dir
05/16/2017  11:33 AM            69,240 hello.c
05/16/2017  11:47 AM            15,872 hello.cp35-win_amd64.pyd
05/16/2017  11:32 AM                17 hello.pyx
(...)
TL;DR——整件事:

where cl >nul 2>nul || "%VS140COMNTOOLS%..\..\VC\vcvarsall.bat" amd64
set INCLUDE=C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt
set LIB=C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10240.0\um\x64;C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10240.0\ucrt\x64
python setup.py build_ext --inplace

我也遇到了同样的问题,通过安装Windows 10 SDK解决了这个问题。

我在尝试安装
pyshark
时收到了同样的错误,我通过在
Developer Command Prompty for VS 2017
中运行
pip install pyshark
并确保安装了VC++工具来解决这个问题。

您需要Windows 10 SDK, 下载并安装

  • VisualC++构建工具的核心特性。 MSVC工具集C++ 2019 V142(x86,x64)
  • 用于桌面C的Windows 10 SDK(10.0.17763.0)++

  • 在您的环境路径中添加windows 10 sdk

    C:\Program Files(x86)\Windows工具包\10\Include\\ucrt

  • 应用更改
  • 打开具有管理员权限的新命令提示符

  • 应该删除此错误。

    如果有人在试图安装
    Git Bash
    时遇到此错误(我想这也适用于使用
    Visual Studio
    编译器在
    Windows
    上运行的任何
    Bash
    shell),那么您可以执行以下操作:

    INCLUDE="C:/Program Files (x86)/Windows Kits/10/Include/10.0.17763.0/ucrt/;C:/Program Files (x86)/Windows Kits/10/Include/10.0.17763.0/shared/" \
    > LIB="C:/Program Files (x86)/Windows Kits/10/Lib/10.0.17763.0/ucrt/x64;C:/Program Files (x86)/Windows Kits/10/Lib/10.0.17763.0/um/x64" \
    > PATH=$PATH:/c/Program\ Files\ \(x86\)/Windows\ Kits/10/bin/10.0.17763.0/x64 \
    > python -m pip install <package>
    

    可通过添加包含目录和库目录来解决此问题,如下所示:

    set INCLUDE=C:\Program Files (x86)\Windows Kits\10\Include\10.0.10150.0\ucrt;E:\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include;C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\shared;E:\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\lib\onecore\x64;C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib\amd64;C:\Program Files (x86)\Windows Kits\10\bin\10.0.17763.0\x64
    
    如果您现在遇到问题:linkerror可以与rc.exe一起运行;
    您还需要将rc.exe和rc.dll(x64)复制到目录,该目录与运行的
    link.exe相同,这是因为Cython需要Windows SDK提供的库。
    要解决此问题,请执行以下操作:

    INCLUDE="C:/Program Files (x86)/Windows Kits/10/Include/10.0.17763.0/ucrt/;C:/Program Files (x86)/Windows Kits/10/Include/10.0.17763.0/shared/" \
    > LIB="C:/Program Files (x86)/Windows Kits/10/Lib/10.0.17763.0/ucrt/x64;C:/Program Files (x86)/Windows Kits/10/Lib/10.0.17763.0/um/x64" \
    > PATH=$PATH:/c/Program\ Files\ \(x86\)/Windows\ Kits/10/bin/10.0.17763.0/x64 \
    > python -m pip install <package>
    
  • 安装Visual Studio 2019的生成工具。从下载。
  • 运行VS构建工具安装文件(VS_buildtools.exe)。选择:
      MSVC构建工具(MSVC V142- VS 2019 C++ X64/x86构建工具)
    • Windows10SDK
  • 安装VS构建工具,需要大约3 GB的空间
  • 从开始菜单,运行VS2019的开发者命令提示符。
  • 转到Cython开发目录,然后运行:
    python setup.py build\u ext--inplace
  • 希望这能解决你的问题

  • 如果您在系统中安装了任何其他“Visual Studio生成工具”,请卸载
  • 重新启动系统
  • 从以下URL下载“Visual Studio 2019构建工具”,然后安装它。 网址: EXE:vs_buildtools_u559949468.1570880880854.EXE
  • 重新启动系统
  • 在管理模式下打开CMD,并尝试安装py软件包。我在安装pyahocarasickpyodbc软件包时遇到问题
  • 安装上述工具后,请签入您的添加/删除程序。

  • 我通过在C++桌面开发中添加以下软件包解决了这个问题


    我试图用VS2017在Windows 10上进行移植和构建,但遇到了相同的错误:“未找到io.h”

    为了弄清楚为什么找不到“io.h”,终端输出可能会给出提示,即包含目录的方式
    set INCLUDE=C:\Program Files (x86)\Windows Kits\10\Include\10.0.10150.0\ucrt;E:\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include;C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\shared;E:\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\lib\onecore\x64;C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib\amd64;C:\Program Files (x86)\Windows Kits\10\bin\10.0.17763.0\x64
    
    set LIB=E:\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\lib\onecore\x64;C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib\amd64;C:\Program Files (x86)\Windows Kits\10\Lib\10.0.17763.0\um\x64;C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10240.0\um\x64;C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10240.0\ucrt\x64
    
    -IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt
    
    -IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt