Cannot open include file: 'io.h': No such file or directory

Solution 1:

You need windows 10 SDK, Download visual studio build tools and install

  1. Visual C++ Build tools core features.
  2. MSVC toolset C++ 2019 v142 (x86,x64)
  3. Visual C++ 2019 Redistributable Update
  4. Windows 10 SDK (10.0.17763.0) for Desktop C++

the image from Rivalus

Solution 2:

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 INCLUDE pointing to the location of io.h - allowing the VS compiler to locate the header.

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.

Solution 3:

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.

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.

(BTW, for others: Python 3.5 needs VS2015, not any other version. Community edition is OK)

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).

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\10\Include\10.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\10\Lib\10.0.10240.0\um\x64;C:\Program Files (x86)\Windows Kits\10\Lib\10.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:

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

Solution 4:

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.

For VS 2017 the various batch files all call:

C:\Program Files (x86)\Microsoft Visual Studio\Shared\14.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 Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat

or

C:\Program Files (x86)\Microsoft Visual Studio\2017\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.