Running Cython in Windows x64 - fatal error C1083: Cannot open include file: 'basetsd.h': No such file or directory
Asked Answered
M

6

48

I have been trying to install Cython for Python 2.7 on my Window 7 system. In particular, I prefer everything in 64 bits. (In case you wonder, I need Cython because Cython is one of the components I need for another package for some specialized numerical analysis. And x64 is potentially an advantage for storage of large data sets.)

So I downloaded the x64 Python 2.7 from the official website. Got Cython from Christoph Gohlke. The amd64 version for Python 2.7 of course. Before I installed, I added Python 2.7 into the registry with the .reg file found in Joe DF's answer here. Afterwards, I installed the Visual C++ compiler from here (I don't think it works) and here (but this one should). At this point, I have in my C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin directory all of vcvars32.bat, vcvars64.bat, vcvars86_amd64.bat, vcvarsx86_ia64.bat. I ran vcvars64.bat and there was no error message.

Subsequently, I followed this page to create a "hello world" test file.

Then, I got this error.

...\Tests>python setup.py build_ext --inplace
running build_ext
building 'hello' extension
error: Unable to find vcvarsall.bat

So I thought to myself: Well, Cython can't find that file because it does not exist. (I searched my whole harddrive for it.) So I copied vcvars64.bat from ...\VC\bin to \VC and changed the name to vcvarsall.bat. Now vcvarsall error is gone. And ... naturally, a new error emerges.

...\Tests>python setup.py build_ext --inplace
running build_ext
building 'hello' extension
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\amd64\cl.exe /c /nolog
o /Ox /MD /W3 /GS- /DNDEBUG -IC:\Python27\include -IC:\Python27\PC /Tchello.c /F
obuild\temp.win-amd64-2.7\Release\hello.obj
hello.c
C:\Python27\include\pyconfig.h(227) : fatal error C1083: Cannot open include fil
e: 'basetsd.h': No such file or directory
error: command '"C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\amd64
\cl.exe"' failed with exit status 2

Now I have no idea how to proceed. What should I do? Your help is much appreciated.

(For clarity, I did try setting the compiler to Mingw32. But there are other errors. I am focusing on getting VC to work for now.)


EDIT: I tried using the SDK build environment CMD following the instructions on this page. I received the same error.

Misdate answered 16/5, 2014 at 2:8 Comment(4)
I hope this helps.Blaeberry
Hi SAM, I am aware of the variable VS90COMNTOOLS. Cython actually searches the VC directory first before going to VS90COMNTOOLS. And at least within the initial steps of building, Cython is able to locate the VC components as described in the question text. Thank you though.Misdate
have you checked (a) that the file is installed and where and (b) what the compiler is including using /showincludes and finally (c) verified that item is not hidden by a compiler directive? If you check the cl.exe help /? then you should be able to make is much much more verbose.Landonlandor
Hi Preet, I just found out neither basetsd.h or windows.h (another header file mentioned in the building C++ program page. msdn.microsoft.com/en-us/library/z7kx322x.aspx) I wonder why thoughMisdate
G
54

In case anyone is currently (2017) facing same error with visual C++ 2015 tools, launch setup again and also select windows 8.1 / 10 SDK depending upon your OS. This will fix basestd.h error.

If it is still not working, try launching build tools from: C:\Program Files (x86)\Microsoft Visual C++ Build Tools.

Another alternative would be, just install anaconda 2 or 3 (64 bit if also you don't want memory errors). It contains all the important packages prebuilt: sklearn, matplotlib, scipy, numpy, pandas and even web development frameworks such as flask.

Grassquit answered 6/3, 2017 at 11:40 Comment(8)
I've chosen win8.1 option on Windows 7. pandas has been built fine. Thanks.Kobold
This helped me with 32bit Windows 10 for installing Geemusic requirements.txt. Worked after I've installed Windows 10 SDK. Thanks ;)Cardholder
Specifically installing the Windows headers option has helped!Raddy
2018. I can't believe it but installing win 10 sdk 64 fixed my basestd.h issue and let me install scikit-imageHalifax
2021. I also can't believe it but installing win 10 sdk 64 fixed my basestd.h issue and let me install pybulletOceania
2022. I also can't believe it but installing win 10 sdk 64 fixed my basestd.h issue and let me install bottleneckRouen
2023. I also can't believe it but installing win 10 sdk 64 fixed my basestd.h issue and let me install pycryptodomeHeard
Years later - installing Windows 11 SDK worked perfect. I encountered the "rc" issue described by daytony as well below, and the answer in the link also worked for me.Stibine
B
24

For those with Windows 10, download the SDK from here to fix the header file basestd.h.

I downloaded the .exe, installed and worked great. SDK was ~2.3GB.

Note: For those like me with 64-bit systems who got an additional error:

`LINK : fatal error LNK1158: cannot run 'rc.exe'
    error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\link.exe' failed with exit status 1158

There is a great answer here which solves the problem by placing the rc.exe file in the correct folder for your system.

Blackstone answered 2/7, 2017 at 5:11 Comment(6)
Anaconda + windows data center server - this is the only solution worked. Here is the actual error: Found executable C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe geometry.c c:\programdata\anaconda3\include\pyconfig.h(222): fatal error C1083: Cannot open include file: 'basetsd.h': No such file or directoryRhyner
This was useful, but I also needed to copy the rcdll.dll file too, else I get a link.exe failed error statement. See https://mcmap.net/q/357275/-python-installing-clarifai-gt-vs14-0-link-exe-failed-with-exit-status-1158Hilaire
did not fix for me(Daguerre
bloody hell that was annoying! glad it works now. Thanks buddy, many thanks for the link.Jannette
Thank you! I was trying to run 'pip install twofish' and the error lead me here, which solved the problem!Bouchier
Years later - and yes, perfect, this resolved this part of the issue for me as well, thanks!Stibine
K
23

I encountered this problem while trying to install pandas in 'develop' mode. I'm up & running now. My environment:

  • Windows XP Pro x64 SP2
  • WinPython 64bit 2.7.5.3 (Python 2.7.5.amd64) <-- "registered" as system's python distro using WinPython Control Panel application

Problems encountered when running python setup.py develop:

  • Unable to find vcvarsall.bat
  • fatal error C1083: Cannot open include file: 'basetsd.h': No such file or directory ... exit code 2

Solution:

  1. Download and install Microsoft Visual C++ 2008 Express.
  2. Download and install Microsoft Windows SDK for Windows 7 and .NET Framework 3.5 SP1. You will need only:
    • Developer Tools > Windows Headers and Libraries <-- this gives you basetsd.h
    • Developer Tools > Visual C++ Compilers <-- this gives you the 64-bit compilers
  3. Copy C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\vcvars64.bat to C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\amd64\vcvarsamd64.bat. Observe the change in file name.
  4. Add C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin to PATH. This may not be required (I did so before re-installing the SDK w/ Headers & Libs; therefore, the necessity is unknown).

At this point, running python setup.py develop completed successfully and python -c "import pandas; print pandas.__version__" resulted in the git tag I expected.

[EDIT] Further reading:

Kagoshima answered 9/9, 2014 at 0:16 Comment(2)
Thats awesome. On a related note, do you know where\how to download Windows SDK for Windows 7 directly, without the web installer?Cranium
Sorry @LucasSoares I don't know where you might find thatKagoshima
A
1

For suggestion, you can try it for build cython 64 bit with setup.py

I'm using Anaconda for python distribution, Microsoft's Windopws SDK 7, and MSVC 12.0.

Firstly, I make library for my cuda function, Second, I run python setup.py build_ext -i for make temp folder (you wil get error), then compile Makefile below,

Mostly, I get this from setup.py when it is compile 32 bit app, then change it for compile 64 bit.

Makefile

CL_EXE      = "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\amd64\cl.exe"
LINK_EXE    = "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\amd64\link.exe"

CL_FLAGS    = /c /nologo /Ox /MD /W3 /GS- /DNDEBUG /O2 /fp:fast
CL_INC      = -I. -I"C:\Program Files\Microsoft SDKs\Windows\v7.1\Include" \
            -I"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include" -IC:\Users\name\Anaconda2\envs\py27\Lib\site-packages\numpy\core\include -IC:\Users\name\Anaconda2\envs\py27\include -IC:\Users\name\Anaconda2\envs\py27\PC 

LINK_FLAGS      = /DLL /nologo /INCREMENTAL:NO /MACHINE:X64
LINK_LIBPATH    = "/LIBPATH:C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5\lib\x64" \
                    /LIBPATH:C:\Users\name\Anaconda2\envs\py27\libs \
                    /LIBPATH:C:\Users\name\Anaconda2\envs\py27\PCbuild\amd64 \
                    /LIBPATH:C:\Users\name\Anaconda2\envs\py27\PC\VS9.0\amd64 \
                    "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\lib\amd64" \
                    "/LIBPATH:C:\Program Files\Microsoft SDKs\Windows\v7.1\Lib\x64"
LINK_LIB        = cuda_multiply4D.lib cudart.lib MSVCRT.lib kernel32.lib
LINK_EXPORT     = /EXPORT:initmy_cuda
LINK_OBJ        = build\temp.win-amd64-2.7\Release\my_cuda.obj
LINK_OUT        = "/OUT:E:\my_cuda.pyd"
LINK_OTHER_CONF = /IMPLIB:build\temp.win-amd64-2.7\Release\my_cuda.lib /MANIFESTFILE:build\temp.win-amd64-2.7\Release\my_cuda.pyd.manifest 

all:
    $(CL_EXE) $(CL_FLAGS) $(CL_INC) /Tcmy_cuda.c /Fobuild\temp.win-amd64-2.7\Release\my_cuda.obj
    $(LINK_EXE) $(LINK_FLAGS) $(LINK_LIBPATH) $(LINK_LIB) $(LINK_EXPORT) $(LINK_OBJ) $(LINK_OUT) $(LINK_OTHER_CONF)

Note:

  • MSVCRT.lib kernel32.lib are optional,
  • /EXPORT:initmy_cuda is mandatory. Its format init%yourfilename_WO_Ext%
  • "/OUT:E:\my_cuda.pyd" for determine your output location, its filename, and its extension.
Amersfoort answered 26/10, 2016 at 8:49 Comment(0)
D
1

Add these to the visual studio installation directories to your Environment variables

C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC

C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin

C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools

hope it solves the issue.

Discernible answered 30/9, 2018 at 12:58 Comment(1)
While those directories did exist, it did not help for meGoldstein
S
0

I could solve this problem by downloading and installing the latest Windows 10 SDK from this link: https://software-download.microsoft.com/download/pr/19041.685.201201-2105.vb_release_svc_prod1_WindowsSDK.iso

but then another problem appeared with (cpython):

error C2039: 'exc_type': is not a member of '_ts'

which I could resolve by declaring additional pointers in

(...\python38\include\cpython\pystate.h)

I found these at line 77:

/* The exception currently being raised */
PyObject *curexc_type;
PyObject *curexc_value;
PyObject *curexc_traceback;

and I add the following just after them (without the first three letters "cur"):

/* The exception currently being raised */
PyObject *exc_type;
PyObject *exc_value;
PyObject *exc_traceback;
Shallow answered 20/12, 2020 at 7:22 Comment(1)
Having to rename internal details of the Python headers suggests to that you've messed something up. I'd guess you're using a 3-year old version of Cython that isn't compatible with Python 3.8. Your "solution" is not a solution and you should expect your program to break in unexpected waysTorrie

© 2022 - 2024 — McMap. All rights reserved.