Python 在 Windows x64 中运行 Cython - 致命错误 C1083:无法打开包含文件:'basetsd.h':没有这样的文件或目录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23691564/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 03:20:51  来源:igfitidea点击:

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

pythonwindowspython-2.7cythonpython-extensions

提问by Argyll

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

我一直在尝试在我的 Window 7 系统上安装 Cython for Python 2.7。特别是,我更喜欢 64 位的所有内容。(如果你想知道,我需要 Cython,因为 Cython 是我需要的另一个包的组件之一,用于一些专门的数值分析。x64 是存储大型数据集的潜在优势。)

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 .regfile 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\bindirectory all of vcvars32.bat, vcvars64.bat, vcvars86_amd64.bat, vcvarsx86_ia64.bat. I ran vcvars64.batand there was no error message.

所以我从官网下载了x64 Python 2.7。从Christoph Gohlke 那里得到Cython。当然是 Python 2.7 的 amd64 版本。在安装之前,我将 Python 2.7 添加到注册表中,并.regJoe DF 的回答here 中找到了该文件。之后,我从这里(我认为它行不通)和这里(但应该是这个)安装了 Visual C++ 编译器。此时,我的C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin目录中包含所有vcvars32.bat, vcvars64.bat, vcvars86_amd64.bat, vcvarsx86_ia64.bat。我跑了vcvars64.bat,没有错误信息。

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

随后,我按照这个页面创建了一个“hello world”测试文件。

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.batfrom ...\VC\binto \VCand changed the name to vcvarsall.bat. Now vcvarsall error is gone. And ... naturally, a new error emerges.

所以我心想:嗯,Cython 找不到那个文件,因为它不存在。(我搜索了我的整个硬盘驱动器。)所以我vcvars64.bat...\VC\binto复制\VC并将名称更改为vcvarsall.bat. 现在 vcvarsall 错误消失了。并且……自然而然地,出现了一个新的错误。

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

(为了清楚起见,我确实尝试将编译器设置为 Mingw32。但还有其他错误。我现在专注于让 VC 工作。)



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

编辑:我尝试按照此页面上的说明使用 SDK 构建环境 CMD 。我收到了同样的错误。

回答by patricktokeeffe

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

我在尝试以pandas“开发”模式安装时遇到了这个问题。我现在正在运行。我的环境:

  • Windows XP Pro x64 SP2
  • WinPython64bit 2.7.5.3 (Python 2.7.5.amd64) <--"registered" as system's python distro using WinPython Control Panel application
  • Windows XP Pro x64 SP2
  • WinPython64bit 2.7.5.3 (Python 2.7.5.amd64)<--使用 WinPython 控制面板应用程序“注册”为系统的 Python 发行版

Problems encountered when running python setup.py develop:

运行时遇到的问题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
  • 无法找到 vcvarsall.bat
  • 致命错误 C1083:无法打开包含文件:'basetsd.h':没有这样的文件或目录...退出代码 2

Solution:

解决方案:

  1. Downloadand install Microsoft Visual C++ 2008 Express.
  2. Downloadand 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.batto 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\binto PATH. This may not be required (I did so before re-installing the SDK w/ Headers & Libs; therefore, the necessity is unknown).
  1. 下载并安装 Microsoft Visual C++ 2008 Express。
  2. 下载并安装适用于 Windows 7 和 .NET Framework 3.5 SP1 的 Microsoft Windows SDK。您只需要:
    • 开发人员工具 > Windows 头文件和库<--这给你basetsd.h
    • 开发人员工具 > Visual C++ 编译器<--这为您提供 64 位编译器
  3. 复制C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\vcvars64.batC:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\amd64\vcvarsamd64.bat. 观察文件名的变化。
  4. 添加C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\binPATH. 这可能不是必需的(我在重新安装带有头文件和库的 SDK 之前这样做了;因此,未知必要性)。

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

此时,运行python setup.py develop成功完成并python -c "import pandas; print pandas.__version__"产生了我预期的 git 标签。

[EDIT]Further reading:

[编辑]进一步阅读:

回答by Khalif21

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

作为建议,您可以尝试使用 setup.py 构建 cython 64 位

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

我将 Anaconda 用于 python 发行版、Microsoft 的 Windopws SDK 7 和 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,

首先,我为我的 cuda 函数创建库,其次,我运行 python setup.py build_ext -i for make temp 文件夹(你会得到错误),然后编译下面的 Makefile,

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

大多数情况下,我在编译 32 位应用程序时从 setup.py 获取它,然后将其更改为编译 64 位。

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.
  • MSVCRT.lib kernel32.lib 是可选的,
  • /EXPORT:initmy_cuda 是强制性的。其格式为 init%yourfilename_WO_Ext%
  • "/OUT:E:\my_cuda.pyd" 用于确定您的输出位置、文件名和扩展名。

回答by Varun Garg

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

如果任何人目前(2017 年)在使用 Visual C++ 2015 工具时遇到同样的错误,请再次启动设置并根据您的操作系统选择 Windows 8.1 / 10 SDK。这将修复basestd.h错误。

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

如果它仍然不起作用,请尝试从以下位置启动构建工具: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.

另一种选择是,只需安装 anaconda 2 或 3(如果您也不希望出现内存错误,则为 64 位)。它包含所有预先构建的重要包:sklearn、matplotlib、scipy、numpy、pandas,甚至是 Flask 等 Web 开发框架。

回答by Dermot McGrath

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

对于使用 Windows 10 的用户,请从此处下载 SDK以修复头文件basestd.h.

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

我下载了 .exe,安装并运行良好。SDK 约为 2.3GB。

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

注意:对于像我这样使用 64 位系统的人来说,遇到了额外的错误:

`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 herewhich solves the problem by placing the rc.exefile in the correct folder for your system.

这里有一个很好的答案它通过将rc.exe文件放在系统的正确文件夹中来解决问题。

回答by Khan

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

将这些添加到 Visual Studio 安装目录到您的环境变量

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.

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

希望它能解决问题。