本文介绍了是否可以在Windows *上*不安装Visual Studio 2008的情况下为Python 2.7至3.1开发C扩展?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道Windows上的Python扩展通常必须使用与编译Python本身相同的Visual Studio版本构建,并且我进一步意识到Python 2.7至3.1是使用Visual Studio 2008构建的.我所在的计算机已经安装了VS 2013,并且,正如我发现的无数次一样,快速弄乱Windows开发环境的一种方法是以从旧到最新的任何顺序安装Visual Studio.除此之外,在全新的Windows 8.1盒子上安装VS2008似乎很愚蠢. Python扩展是我唯一需要2008年的东西.如果我可以避免安装它,我真的不愿意.

I'm aware that Python extensions on Windows typically have to be built with the same version of Visual Studio used to compile Python itself, and I'm further aware that Python 2.7 through 3.1 are built using Visual Studio 2008. But the machine I'm on already has VS 2013 installed, and, as I've discovered countless times, one way to rapidly mess up your Windows development environments is to install Visual Studio in any order than from oldest to newest. Besides which, install VS2008 on a brand-new Windows 8.1 box seems silly. Python extensions are the only thing I have that needs 2008; if I can avoid installing it, I'd really prefer not to.

我是否可以避免安装VS 2008,并且仍然可以通过安装特定的Platform SDK来针对正式的Python发行版进行构建?如果没有,是否有可能与例如Python一起使用的替代Python版本MinGW,还是不需要我安装VS 2008的东西?

Can I avoid installing VS 2008 and still build against the official Python distributions, perhaps by installing a specific Platform SDK? If not, is there an alternative build of Python that might go with e.g. MinGW, or something that does not require I install VS 2008?

推荐答案

我可以为您的问题提出一些可能的解决方案.从可能最简单到可能最困难:

I can suggest a few possible solutions to your problem. From potentially the easiest, to probably the hardest:

  1. 只需使用Visual Studio 2013编译扩展模块.为此,扩展模块不得访问Python解释器创建的任何C运行时对象,也不得将其创建的任何C运行时对象传递给解释器.特别是您不能使用Python提供的任何FILE *或文件描述符对象.您仍然可以读取和写入模块中的文件,而不能读取和读取Python已打开的文件.

  1. Just use Visual Studio 2013 to compile your extension modules. For this to work your extension module mustn't access any C runtime objects created by the Python interpreter, nor may it pass any C runtime objects it creates to the interpreter. In particular you can't use any FILE * or file descriptor objects provided by Python. You can still read and write to files in your module, just not files that Python has opened.

卸载Visual Studio 2013,安装Visual Studio 2008,重新安装Visual Studio2013.听起来这很愚蠢,它可能比以下两种解决方案都更快,更省力.这将使您可以正常地构建扩展模块,而不必担心使用什么C运行时对象.

Uninstall Visual Studio 2013, install Visual Studio 2008, reinstall Visual Studio 2013. As silly as this sounds it's probably going to be a quicker and lot less frustrating than either of the following solutions. This will let you build extension modules pretty much normally and you won't have to worry about what C runtime objects you use.

使用mingw32并利用各种技巧使其正常工作.本页说明了一个人如何工作: https://lists.launchpad.net/kicad-developers/msg09473.html

Use mingw32 and employ various hacks to get it to work. This page explains how one person got it to work: https://lists.launchpad.net/kicad-developers/msg09473.html

从另一台计算机上安装的VS 2008复制相应的msvcrt * .lib文件.手动编辑链接器选项以使用此库,而不是VS 2013的同名msvcrt * .lib.如果这不起作用,请同时复制包含文件和其他库,然后修改编译器和链接器选项以使用它们.如果仍然无法解决问题,请复制VS 2008命令行编译器及其所有相关DLL,正确设置PATH,然后修改构建过程以改用该编译器.

Copy the appropriate msvcrt*.lib file from VS 2008 installed on another machine. Manually edit your linker options to use this library instead of VS 2013's msvcrt*.lib of the same name. If that doesn't work, copy the include files and other libraries as well, and modify your compiler and linker options to use them instead. If that still doesn't work, copy the VS 2008 command line compiler and all of its dependent DLLs, set the PATH correctly, and then modify your build process to use that compiler instead.

这篇关于是否可以在Windows *上*不安装Visual Studio 2008的情况下为Python 2.7至3.1开发C扩展?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 23:48