如何使用 cython 编译扩展?

发布于 12-15 10:23 字数 1468 浏览 2 评论 0原文

我正在尝试从示例页面 此处 编译一个简单的 cython 扩展安装了 Python 2.6 64 位版本的 Windows 7 64 位计算机。我从 Gohlke 页面

基本上,答案来自此处这里不是我的选择,因为我确实需要Python 64位版本来解决更大的内存。另外,因为我尝试使用 Microsoft SDK for .NET 4< 进行编译/a>,我无法使用后一个解决方案中的方法。

我尝试了此处的步骤并观察到绿色窗口,但编译现在抛出无法找到vcvarsall。蝙蝠错误。以下是我尝试过的命令序列:

C:\>cd "Program Files\Microsoft SDKs\Windows\v7.1\"
C:\Program Files\Microsoft SDKs\Windows\v7.1>set DISTUTILS_USE_SDK=1
C:\Program Files\Microsoft SDKs\Windows\v7.1>setenv /x64 /release

Setting SDK environment relative to C:\Program Files\Microsoft SDKs\Windows\v7.1\.
Targeting Windows 7 x64 Release

C:\Program Files\Microsoft SDKs\Windows\v7.1>e:

E:\>cd cython

E:\cython>python setup.py build_ext --inplace
running build_ext
skipping 'fib.c' Cython extension (up-to-date)
building 'fib' extension
error: Unable to find vcvarsall.bat

关于如何解决这个问题有什么建议吗?

I am trying to compile a simple cython extension from the example page here on my Windows 7 64-bit machine with Python 2.6 64-bit version installed. I installed Cython 0.15.1 for Windows 64-bit version from Gohlke's page.

Basically, the answer from here and here are not my options because I really do need Python 64-bit version to address larger memory. Also, because I am trying to compile using Microsoft SDK for .NET 4, I cannot use the approach in the latter solution.

I tried the steps here and observed the green window but compilation now throws the cannot find vcvarsall.bat error. Following is the sequence of commands I tried:

C:\>cd "Program Files\Microsoft SDKs\Windows\v7.1\"
C:\Program Files\Microsoft SDKs\Windows\v7.1>set DISTUTILS_USE_SDK=1
C:\Program Files\Microsoft SDKs\Windows\v7.1>setenv /x64 /release

Setting SDK environment relative to C:\Program Files\Microsoft SDKs\Windows\v7.1\.
Targeting Windows 7 x64 Release

C:\Program Files\Microsoft SDKs\Windows\v7.1>e:

E:\>cd cython

E:\cython>python setup.py build_ext --inplace
running build_ext
skipping 'fib.c' Cython extension (up-to-date)
building 'fib' extension
error: Unable to find vcvarsall.bat

Any suggestions on how I solve this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

凉世弥音2024-12-22 10:23:09

以下是我的批处理文件之一的摘录:

rem Configure the environment for 64-bit builds.
rem Use "vcvars32.bat" for a 32-bit build.
"C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\vcvars64.bat"
rem Convince setup.py to use the SDK tools.
set MSSdk=1
set DISTUTILS_USE_SDK=1 

7.1 SDK 使用的实际上是 VS2010,但 Python 2.6 是使用 VS2008 编译的。如果您可以使用7.0 SDK(我认为它也称为.NET 3.5 SDK),您将可以访问VS2008的编译器。混合不同的编译器和运行时库是有风险的。

Here is an excerpt from one of my batch files:

rem Configure the environment for 64-bit builds.
rem Use "vcvars32.bat" for a 32-bit build.
"C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\vcvars64.bat"
rem Convince setup.py to use the SDK tools.
set MSSdk=1
set DISTUTILS_USE_SDK=1 

The 7.1 SDK uses what is effectively VS2010 but Python 2.6 is compiled with VS2008. If you can use the 7.0 SDK (I think it is also known as the .NET 3.5 SDK), you will have access to VS2008's compiler. It is risky to mix different compilers and runtimes libraries.

零度°2024-12-22 10:23:09

http://wiki.cython.org/64BitCythonExtensionsOnWindows 上的文档说:

对于 Python 2.6、2.7 和 3.1,您应该使用 Microsoft Windows SDK
适用于 Windows 7 和 .NET Framework 3.5 SP1。较新或较早版本
SDK 将链接到错误的 C 运行时。请注意,以后的版本
Python 可能需要更新版本的 Windows
SDK。这是确保扩展程序与
与 Python 相同的 C 运行时版本。使用正确版本的 SDK
是使用 Microsoft 构建工具控制此问题的唯一方法。

The docs at http://wiki.cython.org/64BitCythonExtensionsOnWindows say:

For Python 2.6, 2.7 and 3.1, you should use the Microsoft Windows SDK
for Windows 7 and .NET Framework 3.5 SP1. Later or earlier versions of
the SDK will link with the wrong C runtime. Note that later versions
of Python is likely to require a more recent version of the Windows
SDK. This is required to make sure the extension is linked with the
same C runtime version as Python. Using the correct version of the SDK
is the only way to control this with Microsoft's build tools.

夏日落2024-12-22 10:23:09

微软现在有专门针对Python 2.7的ac编译器包。

我建议你使用它来代替 SDK 和 VS。 VS Express 版本没有 64 位编译器,这就是理论上您需要 SDK 的原因。我尝试安装 SDK 但没有帮助。如果您不需要 SDK 或 VS 进行其他操作,请卸载它们并使用 http://www.microsoft.com/en-gb/download/details.aspx?id=44266

如果安装编译器后仍然遇到问题,我对 pyusb 2.7 Windows 安装错误 可能会有所帮助。

Microsoft have a c compiler package specifically for Python 2.7 now.

I suggest you use that instead of the SDK and VS. The VS express edition doesn't have the 64-bit compiler, which is why you need the SDK, in theory. I tried installing the SDK but it didn't help. If you don't need the SDK or VS for anything else, uninstall them and use the compilers from http://www.microsoft.com/en-gb/download/details.aspx?id=44266.

In the event that you still have problems once you install the compilers, my answer on pyusb 2.7 windows install error may be helpful.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文