Cannot open include file: ‘io.h’: No such file or directory in Python

The error: Cannot open include file: ‘io.h’: No such file or directory in Python is very common in Python, the error happens when you try to compile a .pyx file using Cython.

The following article is a description of the problem and how you can go about solving it with multiple possible solutions.

Explaining The Error : Cannot open include file: ‘io.h’: No such file or directory in Python

I encountered the error above when I was trying to use Cython in order to compile a .pyx file.

After running the command : python setup.py build_ext –inplace . I get the error bellow:

                                                                           #
Files (x86)\Windows Kits\8.1\include\winrt" /Tchello.c
/Fobuild\temp.win32-3.5\Release\hello.obj  
    hello.c
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
                                                                       #

These are the tools I have installed on my machine, Python 3.5, Visual Studio 2015 and Anaconda Anaconda3, the error was so confusing and after a lot of attempts I found multiple solutions.

Solution 1 : defining the environment variable INCLUDE

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.

The solution that worked for me and the one I found to be easy and fast is the following:

Try defining the environment variable INCLUDE. The variable is pointing to the location of io.h, by doing this you will allow the visual studio compiler to locate the header.

You can change it and start using the universal CRT, thus the location of io.h is the one bellow

                                                                       #
<code><code>C:\Program Files (x86)\Windows Kits\10\Include\&lt;version>\ucrt</code></code>
                                                                       #

This works for visual studio 2015 in my case so depending on your version the location could be different.

Solution 2 : Uninstalling all Microsoft and python related software

In my opinion, this is the second best solution, the solution is simple, you should uninstall all Microsoft and python related software, also anaconda and visual studio.

After that re-install Anaconda, python and VS2015 Express and see if this works.

If none of the solutions above worked, I have other solutions that may help you, with development the key is patience my friend.

Solution 3 : This May Work

I tried to replicate the error and I tested this solution and like many other developers this solved my issue. Follow this step by Step.

First – Get the windows 10 SDK (10.0.17763.0) for Desktop C++

Second – Download the visual studio build tools, then install

  1. Visual C++ Build tools core features.
  2. MSVC toolset C++ 2019 v142 (x86,x64)
  3. Visual C++ 2019 Redistributable Update

If this solved your error, Congrats, now give me your money, just joking, This is free but you can help us by donating to our Kofi account above, it is that red button my friend but you do not have to.

If none of the above solved your problem then you are an unlucky fellow, I have one final solution that I pray will work for you. The one bellow.

Solution 4 : Including directories and library directories

You can solve the issue by adding include dirs and library dirs like in the example bellow:

                                                                       #
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
                                                                       #

It can be solved by adding include dirs and library dirs as follow:

                                                                       #
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
                                                                       #

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

Now you can get the error: link error can run with rc.exe

To solve it, you can copy rc.exe and rc.dll (x64) to the same directory where the running link.exe resides.

Summing-up

Friends, I hope this article was helpful and help you in any way, shape or form, the first solution worked for me and also the third, depending on your case the solution could be different, just keep trying and do not give up, keep coding, cheers.

If you want to learn more about Python, please check out the Python Documentation : https://docs.python.org/3/