Python 无法打开包含文件:'io.h':没有这样的文件或目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40018405/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot open include file: 'io.h': No such file or directory
提问by user2869934
I was trying to compile a simple .pyx file using Cython.
我试图使用 Cython 编译一个简单的 .pyx 文件。
print("hello")
Here's my setup.py:
这是我的 setup.py:
from distutils.core import setup
from Cython.Build import cythonize
setup(
ext_modules = cythonize("hello.pyx")
)
Then I run the command.
然后我运行命令。
python setup.py build_ext --inplace
The error is shown below. I've struggled on googling it but found nothing helpful.
错误如下所示。我一直在努力搜索它,但发现没有任何帮助。
running build_ext building 'hello' extension C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\Users\Hymanie\AppData\Local\Continuum\Anaconda3\include -IC:\Users\Hymanie\AppData\Local\Continuum\Anaconda3\include "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\include\wdf\ucrt" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK.6\include\um" "-IC:\Program Files (x86)\Windows Kits.1\include\shared" "-IC:\Program Files (x86)\Windows Kits.1\include\um" "-IC:\Program Files (x86)\Windows Kits.1\include\winrt" /Tchello.c /Fobuild\temp.win32-3.5\Release\hello.obj hello.c c:\users\Hymanie\appdata\local\continuum\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\cl.exe' failed with exit status 2
running build_ext building 'hello' extension C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\Users\Hymanie\AppData\Local\Continuum\Anaconda3\include -IC:\Users\Hymanie\AppData\Local\Continuum\Anaconda3\include "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\include\wdf\ucrt" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK.6\include\um" "-IC:\Program Files (x86)\Windows Kits.1\include\shared" "-IC:\Program Files (x86)\Windows Kits.1\include\um" "-IC:\Program Files (x86)\Windows Kits.1\include\winrt" /Tchello.c /Fobuild\temp.win32-3.5\Release\hello.obj hello.c c:\users\Hymanie\appdata\local\continuum\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\cl.exe' failed with exit status 2
Can someone help me to resolve the error, please?
有人可以帮我解决这个错误吗?
I have Anaconda3 4.1.1, Python 3.5, and Visual Studio Express 2015 installed.
我安装了 Anaconda3 4.1.1、Python 3.5 和 Visual Studio Express 2015。
回答by bob
Download visual studio build toolsand install
下载Visual Studio 构建工具并安装
- Visual C++ Build tools core features.
- VC++ 2017 v141 toolset (x86,x64)
- Visual C++ 2017 Redistributable Update
- Windows 10 SDK (10.0.16299.0) for Desktop C++
- Visual C++ 构建工具的核心功能。
- VC++ 2017 v141 工具集(x86、x64)
- Visual C++ 2017 可再发行更新
- 用于桌面 C++ 的 Windows 10 SDK (10.0.16299.0)
回答by Calum Atkinson
In case anyone finds this thread and is looking for a quicker solution than reinstalling VS and/or Anaconda - I was able to get past this same error by defining the environment variable INCLUDEpointing to the location of io.h - allowing the VS compiler to locate the header.
万一有人找到这个线程并且正在寻找比重新安装 VS 和/或 Anaconda 更快的解决方案 - 我能够通过定义指向 io.h 位置的环境变量INCLUDE来克服同样的错误- 允许 VS 编译器找到标题。
In my setup, using VS2015, the change to using the Universal CRT means the location of io.h is C:\Program Files (x86)\Windows Kits\10\Include\<version>\ucrt
.
For different versions/environments the location of io.h may differ.
在我的设置中,使用 VS2015,更改为使用 Universal CRT 意味着 io.h 的位置是C:\Program Files (x86)\Windows Kits\10\Include\<version>\ucrt
. 对于不同的版本/环境,io.h 的位置可能不同。
回答by Justin Kirk
Microsoft doesn't make any effort to make console development steps obvious anymore. Visual Studio has long been packaged with some batch files to establish environment variables. When the C++ CLI development options are selected in VS2015/2017, there are one or more shortcuts added to the start menu to execute these batch files.
Microsoft 不再努力使控制台开发步骤变得显而易见。Visual Studio 早就打包了一些批处理文件来建立环境变量。在VS2015/2017中选择C++ CLI开发选项时,开始菜单中添加了一个或多个快捷方式来执行这些批处理文件。
For VS 2017 the various batch files all call:
对于 VS 2017,各种批处理文件都调用:
C:\Program Files (x86)\Microsoft Visual Studio\Shared.0\VC\vcvarsall.bat
with specific parameters.
带具体参数。
Rather than setting a System or User Environment Variable, it would be better to call the specific batch file to meet your build needs.
与其设置系统或用户环境变量,不如调用特定的批处理文件来满足您的构建需求。
C:\Program Files (x86)\Microsoft Visual Studio17\Community\VC\Auxiliary\Build\vcvars64.bat
or
或者
C:\Program Files (x86)\Microsoft Visual Studio17\Community\VC\Auxiliary\Build\vcvars32.bat
One thing to bear in mind with Python/Ruby/etc, scripts will often need to elevate the execution shell to Administrator role in order to install packages. If you execute the batch file in a non-Administrator shell, and the package installation requires elevation it will spawn a subshell which will not have the environment variables. Therefore, you should run the batch file in an Administrator shell before calling the package manager or script.
在使用 Python/Ruby/etc 时要记住的一件事是,脚本通常需要将执行 shell 提升到管理员角色才能安装包。如果您在非管理员 shell 中执行批处理文件,并且软件包安装需要提升,它将生成一个没有环境变量的子 shell。因此,您应该在调用包管理器或脚本之前在管理员 shell 中运行批处理文件。
回答by Tomasz Gandor
I stumbled upon the same problem - with very similar configuration to yours (only difference: VS 2015 Pro). After a few weeks on just having to download wheels from other people (e.g. http://www.lfd.uci.edu/~gohlke/pythonlibs/) I finally found a solution which works for me.
我偶然发现了同样的问题 - 与您的配置非常相似(唯一的区别:VS 2015 Pro)。几周后只需要从其他人那里下载轮子(例如http://www.lfd.uci.edu/~gohlke/pythonlibs/)我终于找到了一个适合我的解决方案。
There are 2 problems. Problem 1 - you need to use "Developer Command Prompt" - sometimes there is such a program in Start Menu, then you just use it.
有2个问题。问题 1 - 您需要使用“开发人员命令提示符” - 有时开始菜单中有这样的程序,然后您只需使用它。
(BTW, for others: Python 3.5 needs VS2015, not any other version. Community edition is OK)
(顺便说一句,对于其他人:Python 3.5 需要 VS2015,而不是任何其他版本。社区版是可以的)
If not, you can use the following snippet (in command line):
如果没有,您可以使用以下代码段(在命令行中):
"%VS140COMNTOOLS%vsvars32.bat"
or even:
甚至:
where cl >nul 2>nul || "%VS140COMNTOOLS%vsvars32.bat"
(i have it in a batch file to run my build environment)
(我把它放在一个批处理文件中来运行我的构建环境)
(If you dont have the %VS140COMNTOOLS%
variable, then maybe you just installed the VS and you need e.g. to restart, so that new environment variables become visible).
(如果您没有该%VS140COMNTOOLS%
变量,那么您可能刚刚安装了 VS 并且您需要重新启动,以便新的环境变量可见)。
Now you will get the error:
现在你会得到错误:
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
(as in your edited answer)
(如您编辑的答案)
So now run:
所以现在运行:
set INCLUDE=C:\Program Files (x86)\Windows Kits\Include.0.10240.0\ucrt
OK, now you will get the error:
好的,现在你会得到错误:
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
What now? You need to add library dirs:
现在怎么办?您需要添加库目录:
set LIB=C:\Program Files (x86)\Windows Kits\Lib.0.10240.0\um\x64;C:\Program Files (x86)\Windows Kits\Lib.0.10240.0\ucrt\x64
No errors this time:
这次没有错误:
> 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- the whole thing:
TL; DR- 整个事情:
where cl >nul 2>nul || "%VS140COMNTOOLS%..\..\VC\vcvarsall.bat" amd64
set INCLUDE=C:\Program Files (x86)\Windows Kits\Include.0.10240.0\ucrt
set LIB=C:\Program Files (x86)\Windows Kits\Lib.0.10240.0\um\x64;C:\Program Files (x86)\Windows Kits\Lib.0.10240.0\ucrt\x64
python setup.py build_ext --inplace
回答by Amr Ashraf
I had the same problem, solved it by installing Windows 10 SDK.
我遇到了同样的问题,通过安装 Windows 10 SDK 解决了它。
回答by Kcvin
I received the same error when trying to install pyshark
and I resolved this issue by running pip install pyshark
in Developer Command Prompty for VS 2017
and making sure I had VC++ tools installed.
试图安装时,我收到了同样的错误pyshark
,我通过运行解决这个问题pip install pyshark
的Developer Command Prompty for VS 2017
,并确保我已经安装了VC ++工具。
回答by Khan
Add windows 10 sdk in your environment path.
在您的环境路径中添加 windows 10 sdk。
C:\Program Files (x86)\Windows Kits\10\Include\\ucrt
C:\Program Files (x86)\Windows Kits\10\Include\\ucrt
- apply the changes.
- open a new command prompt with administrator rights.
- 应用更改。
- 使用管理员权限打开一个新的命令提示符。
the error should be removed.
应该删除错误。
回答by rwolst
If anyone is running into this error while trying to install in Git Bash
(I imagine this would also work for any Bash
shell running on Windows
using the Visual Studio
compiler), then you can do the following:
如果有人在尝试安装时Git Bash
遇到此错误(我想这也适用Bash
于Windows
使用Visual Studio
编译器运行的任何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>
For different versions of Windows
and Visual Studio
these paths may be slightly different. The best way to get them is when an error is thrown, search for the file with
对于不同的版本Windows
和Visual Studio
这些路径可能略有不同。获取它们的最佳方法是在抛出错误时,使用以下命令搜索文件
find /c/Program\ Files\ \(x86\)/ -name <name_of_error_causing_file>
回答by u11623747
It can be solved by adding include dirs and library dirs as follow:
可以通过添加包含目录和库目录来解决,如下所示:
set INCLUDE=C:\Program Files (x86)\Windows Kits\Include.0.10150.0\ucrt;E:\Microsoft Visual Studio17\Community\VC\Tools\MSVC.16.27023\include;C:\Program Files (x86)\Windows Kits\Include.0.17763.0\shared;E:\Microsoft Visual Studio17\Community\VC\Tools\MSVC.16.27023\lib\onecore\x64;C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib\amd64;C:\Program Files (x86)\Windows Kits\bin.0.17763.0\x64
set LIB=E:\Microsoft Visual Studio17\Community\VC\Tools\MSVC.16.27023\lib\onecore\x64;C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib\amd64;C:\Program Files (x86)\Windows Kits\Lib.0.17763.0\um\x64;C:\Program Files (x86)\Windows Kits\Lib.0.10240.0\um\x64;C:\Program Files (x86)\Windows Kits\Lib.0.10240.0\ucrt\x64
and if then you are now getting a problem: link error can run with rc.exe;
you also need copy rc.exe and rc.dll (x64) to the dir which is the same with the running link.exe
如果那时您现在遇到问题:链接错误可以使用 rc.exe 运行;您还需要将 rc.exe 和 rc.dll (x64) 复制到与运行相同的目录link.exe
回答by Rivalus
This is because Cython require libraries provided by Windows SDK. To fix this, do the following:
这是因为 Cython 需要 Windows SDK 提供的库。要解决此问题,请执行以下操作:
- Install Build Tools for Visual Studio 2019. Download from here.
- Run VS Build Tools setup files (vs_buildtools.exe). Choose:
- Install VS Build Tools, it will require around 3 GB of space.
- From Start Menu, run Developer Command Prompt for VS 2019.
- Go to your Cython development directory and then run:
python setup.py build_ext --inplace
- 安装 Visual Studio 2019 的构建工具。从这里下载。
- 运行 VS 构建工具安装文件 (vs_buildtools.exe)。选择:
- 安装 VS Build Tools,它将需要大约 3 GB 的空间。
- 从“开始”菜单,运行 VS 2019 的开发人员命令提示符。
- 转到您的 Cython 开发目录,然后运行:
python setup.py build_ext --inplace
Hopefully this will fix your problem.
希望这能解决您的问题。