简体   繁体   English

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

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

I have been trying to install Cython for Python 2.7 on my Window 7 system.我一直在尝试在我的 Window 7 系统上安装 Cython for Python 2.7。 In particular, I prefer everything in 64 bits.特别是,我更喜欢 64 位的所有内容。 (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.) (如果你想知道,我需要 Cython,因为 Cython 是我需要的另一个组件之一,用于一些专门的数值分析。而 x64 是存储大型数据集的潜在优势。)

So I downloaded the x64 Python 2.7 from the official website.所以我从官网下载了x64 Python 2.7。 Got Cython from Christoph Gohlke .Christoph Gohlke 那里得到Cython The amd64 version for Python 2.7 of course.当然是 Python 2.7 的 amd64 版本。 Before I installed, I added Python 2.7 into the registry with the .reg file found in Joe DF's answer here .在安装之前,我将 Python 2.7 添加到注册表中,并在Joe DF 的回答中找到了.reg文件。 Afterwards, I installed the Visual C++ compiler from here (I don't think it works) and here (but this one should).之后,我从 这里(我认为它行不通)和这里(但应该是这个)安装了 Visual C++ 编译器。 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 .此时,我在C:\\Program Files (x86)\\Microsoft Visual Studio 9.0\\VC\\bin目录中拥有所有vcvars32.batvcvars64.batvcvars86_amd64.batvcvarsx86_ia64.bat I ran vcvars64.bat and there was no error message.我运行vcvars64.bat并且没有错误消息。

Subsequently, I followed this page to 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.所以我心里想:嗯,Cython 找不到那个文件,因为它不存在。 (I searched my whole harddrive for it.) So I copied vcvars64.bat from ...\\VC\\bin to \\VC and changed the name to vcvarsall.bat . (我搜索了我的整个硬盘。)所以我将vcvars64.bat...\\VC\\bin复制到\\VC并将名称更改为vcvarsall.bat Now vcvarsall error is gone.现在 vcvarsall 错误消失了。 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.) (为了清楚起见,我确实尝试将编译器设置为 Mingw32。但还有其他错误。我现在专注于让 VC 工作。)


EDIT: I tried using the SDK build environment CMD following the instructions on this page .编辑:我尝试按照此页面上的说明使用 SDK 构建环境 CMD。 I received the same error.我收到了同样的错误。

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.如果任何人目前(2017 年)在使用 Visual C++ 2015 工具时遇到同样的错误,请再次启动设置并根据您的操作系统选择 Windows 8.1 / 10 SDK。 This will fix basestd.h error.这将修复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).另一种选择是,只需安装 anaconda 2 或 3(如果您也不希望出现内存错误,则为 64 位)。 It contains all the important packages prebuilt: sklearn, matplotlib, scipy, numpy, pandas and even web development frameworks such as flask.它包含所有预先构建的重要包:sklearn、matplotlib、scipy、numpy、pandas,甚至是 Flask 等 Web 开发框架。

I encountered this problem while trying to install pandas in 'develop' mode.我在尝试以“开发”模式安装pandas时遇到了这个问题。 I'm up & running now.我现在正在运行。 My environment:我的环境:

  • Windows XP Pro x64 SP2 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 WinPython 64bit 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无法找到 vcvarsall.bat
  • fatal error C1083: Cannot open include file: 'basetsd.h': No such file or directory ... exit code 2致命错误 C1083:无法打开包含文件:'basetsd.h':没有这样的文件或目录...退出代码 2

Solution:解决方案:

  1. Download and install Microsoft Visual C++ 2008 Express.下载并安装 Microsoft Visual C++ 2008 Express。
  2. Download and install Microsoft Windows SDK for Windows 7 and .NET Framework 3.5 SP1.下载并安装适用于 Windows 7 和 .NET Framework 3.5 SP1 的 Microsoft Windows SDK。 You will need only:您只需要:
    • Developer Tools > Windows Headers and Libraries <-- this gives you basetsd.h开发人员工具 > Windows 头文件和库<--这给你basetsd.h
    • Developer Tools > Visual C++ Compilers <-- this gives you the 64-bit compilers开发人员工具 > Visual C++ 编译器<--这为您提供了 64 位编译器
  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 .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 Observe the change in file name.观察文件名的变化。
  4. Add C:\\Program Files (x86)\\Microsoft Visual Studio 9.0\\VC\\bin to PATH .C:\\Program Files (x86)\\Microsoft Visual Studio 9.0\\VC\\binPATH This may not be required (I did so before re-installing the SDK w/ Headers & Libs; therefore, the necessity is unknown).这可能不是必需的(我在重新安装带有头文件和库的 SDK 之前这样做了;因此,未知必要性)。

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.此时,运行python setup.py develop成功完成并且python -c "import pandas; print pandas.__version__"产生了我期望的 git 标签。

[EDIT] Further reading: [编辑]进一步阅读:

For those with Windows 10, download the SDK from here to fix the header file basestd.h .对于使用 Windows 10 的用户,请从此处下载 SDK 以修复头文件basestd.h

I downloaded the .exe, installed and worked great.我下载了 .exe,安装并运行良好。 SDK was ~2.3GB. 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 here which solves the problem by placing the rc.exe file in the correct folder for your system.这里有一个很好的答案它通过将rc.exe文件放在您系统的正确文件夹中来解决问题。

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

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

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

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

hope it solves the issue.希望它能解决问题。

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我可以通过从这个链接下载和安装最新的 Windows 10 SDK 来解决这个问题: https : //software-download.microsoft.com/download/pr/19041.685.201201-2105.vb_release_svc_prod1_WindowsSDK.iso

but then another problem appeared with (cpython):但是(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:我在第 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"):我在它们之后添加以下内容(没有前三个字母“cur”):

/* The exception currently being raised */
PyObject *exc_type;
PyObject *exc_value;
PyObject *exc_traceback;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 致命错误 C1083:无法打开包含文件:“basetsd.h” - fatal error C1083: Cannot open include file: 'basetsd.h' 编译Cython代码产生...致命错误C1083:无法打开包含文件:&#39;io.h&#39; - Compiling Cython code yields… fatal error C1083: Cannot open include file: 'io.h' Could not install pycocotools in windows: fatal error C1083: Cannot open include file: 'io.h': No such file or directory 错误: - Could not install pycocotools in windows: fatal error C1083: Cannot open include file: 'io.h': No such file or directory error: 致命错误 C1083:无法打开包含文件:“mecab.h”:没有这样的文件或目录 - fatal error C1083: Cannot open include file: 'mecab.h': No such file or directory 致命错误 C1083:无法打开包含文件:'io.h':没有这样的文件或目录 - fatal error C1083: Cannot open include file: 'io.h': No such file or directory 致命错误C1083:无法打开包含文件:&#39;openssl / opensslv.h&#39;:没有这样的文件或目录 - fatal error C1083: Cannot open include file: 'openssl/opensslv.h': No such file or directory 致命错误 C1083:无法打开包含文件:'dlfcn.h':没有这样的文件或目录 PyLPSolve - fatal error C1083: Cannot open include file: 'dlfcn.h': No such file or directory PyLPSolve Cython 编译器 - 致命错误 C1083:无法打开包含文件 - Cython compiler - fatal error C1083: Cannot open include file MySQLdb/_mysql.c(29): 致命错误 C1083: 无法打开包含文件: &#39;mysql.h&#39;: 没有这样的文件或目录 - MySQLdb/_mysql.c(29): fatal error C1083: Cannot open include file: 'mysql.h': No such file or directory Python pip install kivy致命错误C1083:无法打开包含文件:&#39;GL / glew.h&#39;:没有这样的文件或目录 - Python pip install kivy fatal error C1083: Cannot open include file: 'GL/glew.h': No such file or directory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM