101

I was trying to compile a simple .pyx file using Cython.

print("hello")

Here's my 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\Jackie\AppData\Local\Continuum\Anaconda3\include -IC:\Users\Jackie\AppData\Local\Continuum\Anaconda3\include "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE"
"-IC:\Program Files (x86)\Windows Kits\10\include\wdf\ucrt"
"-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6\include\um"
"-IC:\Program Files (x86)\Windows Kits\8.1\include\shared"
"-IC:\Program Files (x86)\Windows Kits\8.1\include\um" "-IC:\Program
Files (x86)\Windows Kits\8.1\include\winrt" /Tchello.c
/Fobuild\temp.win32-3.5\Release\hello.obj  
    hello.c
    c:\users\jackie\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.

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
user2869934
  • 1,419
  • 4
  • 13
  • 18
  • Well... the error went away after I uninstalled all Microsoft and python related software and install Anaconda and VS2015 Express again. However, another error came along... – user2869934 Oct 14 '16 at 07:40

18 Answers18

155

Update

if you have Visual Studio 2022 no need to download VS Build Tools, as you can use for the same purpose Visual Studio Installer (located in VS2022 start menu folder)

As pointed out by JfredoJ

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

bob
  • 1,668
  • 1
  • 8
  • 8
31

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.

Calum Atkinson
  • 411
  • 3
  • 3
  • Could you clarify where you change this path? I'm using the "Visual C++ 2015 MSBuild Command Prompt" – Atnas Jan 19 '18 at 14:07
  • 3
    @Atnas You should be able to use the `SET` command from within the prompt. Alternatively, if you want it to persist, you can set it via This PC/My Computer -> Advanced Settings -> Environment Variables and creating a new system wide variable. – Calum Atkinson Jan 19 '18 at 23:05
  • This worked for me but then I got an errror: `cannot open include file: ‘Ws2_32.lib’` Does anyone know how to fix this? – S2673 Nov 07 '20 at 21:25
22

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
Tomasz Gandor
  • 8,235
  • 2
  • 60
  • 55
  • 1
    This was found here: https://devtalk.nvidia.com/default/topic/969047/cuda-8-vs2015-corecrt-h-error/?offset=7 - PyCUDA users have the same problem. – Tomasz Gandor May 16 '17 at 09:52
  • 2
    This solution was exactly what I was looking for. I have been trying for the longest time to solve this issue applying many different solutions. If you have problems running the `"%VS140COMNTOOLS%vsvars32.bat"` with an error saying `"Cannot determine the location of the VS Common Tools folder."`, most likely you are using a laptop from your company and you have restricted access, you can verify by trying `reg query 1` and if it says `Registry editing has been disabled by your administrator.`, then that is the issue – Felipe Araya Olea Apr 26 '21 at 14:10
14

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.

ayushgp
  • 4,891
  • 8
  • 40
  • 75
Justin Kirk
  • 141
  • 1
  • 3
11

This is because Cython require libraries provided by Windows SDK. To fix this, do the following:

  1. Install Build Tools for Visual Studio 2019. Download from here. Build Tools for Visual Studio 2019 download page
  2. Run VS Build Tools setup files (vs_buildtools.exe). Choose:
    • MSVC build tools (MSVC v142 - VS 2019 C++ x64/x86 build tools)
    • Windows 10 SDK Build Tools for Visual Studio 2019 installation
  3. Install VS Build Tools, it will require around 3 GB of space.
  4. From Start Menu, run Developer Command Prompt for VS 2019. Developer Command Prompt for VS 2019
  5. Go to your Cython development directory and then run: python setup.py build_ext --inplace

Hopefully this will fix your problem.

Rivalus
  • 1,052
  • 9
  • 10
10

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

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

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

Rajan Sharma
  • 2,211
  • 3
  • 21
  • 33
大白杨
  • 101
  • 1
  • 3
  • 2
    cant get why this answer so undervalued, only this brilliantly solve this trouble. thanks you so much!! – Dmitry Jan 23 '20 at 15:24
9

I had the same problem, solved it by installing Windows 10 SDK.

Amr Ashraf
  • 419
  • 6
  • 19
4

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:

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

find /c/Program\ Files\ \(x86\)/ -name <name_of_error_causing_file>
rwolst
  • 12,904
  • 16
  • 54
  • 75
3

In addition to the items in the list posted by bob, installing Universal CRT SDK solved the issue for me, so the list becomes:

  1. Visual C++ Build tools core features.
  2. VC++ 2017 v141 toolset (x86,x64)
  3. Visual C++ 2017 Redistributable Update
  4. Windows 10 SDK (10.0.16299.0) for Desktop C++
  5. Windows Universal CRT SDK
sin
  • 89
  • 1
  • 2
  • You could just comment under his solution. This is more of a dublicate. – richardev Aug 27 '20 at 14:03
  • 4
    I wanted to, but it seems that I must have 50 reputations to be able to comment on his answer, and I don't have that many. – sin Aug 28 '20 at 16:50
  • I needed more. I run Visual Studio Installer -> Visual Studio Build Tools 2019. It preselected: C++ BUILD TOOLS C++ Build Tools core features C++ 2019 Redistributable Update C++ core desktop features OPTIONAL MSVC v142 - VS 2019 C++ x64/x86 build tools (v14.28) Windows 10 SDK (10.0.18362.0) C++ CMake tools for Windows Testing tools core features - Build Tools C++ AddressSanitizer (Experimental) MSVC v140 - VS 2015 C++ build tools (v14.00) INDIVIDUAL COMPONENTS Windows Universal CRT SDK MSVC v140 - VS 2015 C++ build tools (v14.00) – Stefan Dec 23 '20 at 19:48
2

I solved the issue by adding the below packages in Desktop development with C++

enter image description here

enter image description here

  • i am in python and try to install fancy impute using pip install but i get the following error (Cannot open include file: 'io.h'). i am try to download windows SDK and add path to environmental variables but aslo failed – mayaaa Dec 22 '19 at 09:10
  • how can i fix it? i think it is the same error here – mayaaa Dec 22 '19 at 09:10
1

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.

Kcvin
  • 5,073
  • 2
  • 32
  • 54
1

Add windows 10 sdk in your environment path.

C:\Program Files (x86)\Windows Kits\10\Include\\ucrt

  1. apply the changes.
  2. open a new command prompt with administrator rights.

the error should be removed.

Khan
  • 1,288
  • 12
  • 11
1

If installing the Build Tools didn't solve the problem, adding/editing 3 system environment variables will probably do

Depending on the versions of the build toold you installed, you might have to modify the paths a bit:

  1. Install Microsoft C++ Build Tools. I included the components MSVC v143 - VS 2022 C++-x64/x86-Buildtools and Windows 11 SDK (10.0.22000.0). The exact versions are probably not that important.
  2. Add system environment variable INCLUDE with (adjust to your versions) value C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\ucrt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\shared. The first directory should contain e.g. io.h and corecrt_wio.h, the second should contain e.g. basetsd.h.
  3. Add system environment variable LIB with value C:\Program Files (x86)\Windows Kits\10\Lib\10.0.22000.0\um\x64;C:\Program Files (x86)\Windows Kits\10\Lib\10.0.22000.0\ucrt\x64.
  4. Add value C:\Program Files (x86)\Windows Kits\10\bin\10.0.22000.0\x86 to the system env. var. Path. This directory should contain rcdll.dll and rc.exe.
  5. reboot system

As Felipe Araya Olea pointed out, installing the Build Tools alone might not suffice due to restricted access to the registry when your e.g. working on a company computer. However, the above steps solved the problem for me.

jonas
  • 181
  • 3
  • 8
  • THIS IS THE ONLY ANSWER, AMONG ALL THE OTHERS, THAT HELPED ME!! THANK YOU THANK YOU THANK YOU!!! – DanielY Apr 18 '23 at 11:24
0
  1. Uninstall if you have installed any other "Visual Studio Build Tools" in you system.
  2. Restart your system.
  3. Download "Build Tools for Visual Studio 2019" from following URL and install it. URL : https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2019 EXE : vs_buildtools__559949468.1570880854.exe
  4. Restart your system.
  5. Open CMD in admin mode, and try to install py packages. For me getting issues while installing pyahocorasick and pyodbc packages etc.
  6. After installing above tool, check in your add remove program. Screenshot of Add remove programs in Control Panel
Chandan
  • 31
  • 1
  • 4
0

I was trying to transplant and build pycocotools on Windows 10 with VS2017, and meet same error: "io.h not found".

To figure out why "io.h" was not found, the terminals output may give hints, i.e. how the including directory are specified. In my case, wrong version of Windows 10 SDK is used:

-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt

instead of

-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt

and there's no C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt (but there is C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0).

Finally, in control panel, I removed Windows Driver Kit 18362 (which was installed via VS2019 but VS2019 was removed later, and this 18362 is not totally uninstalled), and the problem "io.h not found" is solved.


Let me make it more clear:

  • Windows SDK 10.0.17763.0 is introduced via VS2017
  • Windows SDK 10.0.18362.0 is introduced via VS2019 When there are multiple version of Windows SDK (even its directory not contains ucrt folder for including files), the newest one will be picked, which causing "io.h not found" similar error.
ChrisZZ
  • 1,521
  • 2
  • 17
  • 24
0

check folder d:\New folder is accessible because Windows 10 SDK, Download Visual Studio Build tools needs that folder for temp files and errors are as described in these questions if it is not available.

Augustas
  • 1,167
  • 21
  • 31
-2

if anyone has any issues with installing openstack or any other applications that require python or pip (or netifaces, oslo.utils, python-cinderclient, msgpack, oslo.serialization, python-novaclient, PyYAML, pyperclip, colorama, pyreadline, attrs, wcwidth, cmd2, cliff, pycparser, cffi, cryptography, decorator, requestsexceptions, jsonpointer, jsonpatch, munch, jmespath, dogpile.cache, appdirs, OpenStack SDK, rfc3986, oslo.config, python-keystoneclient, osc-lib), and also that uses Visual studio - follow the below steps:

  1. Install python 3.8.5
  2. Pip is installed automatically with python
  3. reboot the system (very important)
  4. enter the cmd to install any app: example: pip install python-openstackclient
-2

I had this annoying error while I was trying to install pyhook 1.5.1. It worked when I

  1. install windows10 SDK (as I am using windows10)
  2. run visual studio x64 command prompt in administrator mode.
  3. take a cold shower.
  4. Finally I press enter.

Yeasss! and it worked.

micky
  • 1
  • 1