2010-02-14 214 views
19

的谷歌应用程序引擎启动器告诉我:如何在Windows上安装Python ssl模块?

WARNING appengine_rpc.py:399 ssl module not found. Without the ssl module, the identity of the remote host cannot be verified, and connections may NOT be secure. To fix this, please install the ssl module from http://pypi.python.org/pypi/ssl .

我下载的软件包,它包含一个setup.py文件。我跑:

python setup.py install 

然后:

Python was built with Visual Studio 2003; blablabla use MinGW32 

然后我安装MINGW32现在的编译不起作用。编译错误的结尾包含:

ssl/_ssl2.c:1561: error: `CRYPTO_LOCK' undeclared (first use in this function)

error: command 'gcc' failed with exit status 1

我该怎么办?

+1

我在win7x64下安装python,并且提示没有ssl,安装setuptools然后pip,最后:pip安装pyOpenSSL。 – BollMose 2014-11-04 08:11:58

+0

@ DienBell的评论是为我解决的(干净安装Windows 8.1,无需编译环境) – WoJ 2015-03-11 14:10:57

回答

15

抓斗由GnuWin32项目openssllibgw32c包您安装的GnuWin32(下载“开发者文件”!),并提取它们 - 或者,如果你没有的GnuWin32工具的是,你可以在任何地方提取它(例如“ C:\ Program Files \ gnuwin32“)。在“setup.py”文件中输入gnuwin32目录(替换第154行中的“C:\ Utils \ GnuWin32”)。

然后你可以建立ssl模块没有问题。我自己测试了它,使用GCC“4.3.2-tdm-2 mingw32”和命令行setup.py build -cmingw32-cmingw32强制MinGW,因为我也安装了Microsoft的编译器)。成功构建后执行setup.py install安装ssl

+2

您链接的openssl安装程序已经安装了libgw32c压缩文件中存在的一些(或全部)文件。 – 2010-02-14 18:57:01

+0

即使在我遵循你的指示之后,我在构建'ssl模块时遇到了同样的问题 – 2010-02-14 18:58:45

+1

对不起,我忘了提及你需要根据你的gnuwin32路径改变setup.py。编辑答案。 – AndiDog 2010-02-14 19:02:03

9

我不得不使用AndiDog的方法的以下修改:

setup.py build -cmingw32 
setup.py install --skip-build 

没有--skip-构建选项,安装会尝试重新建立和再抱怨MSVC:

error: Python was built with Visual Studio 2003; 
extensions must be built with a compiler than can generate compatible binaries. 
Visual Studio 2003 was not found on this system. If you have Cygwin installed, 
you can try compiling with MingW32, by passing "-c mingw32" to setup.py. 

此外,最初使用build命令时,我有很多像这样的错误:

build\temp.win32-2.5\Release\ssl\_ssl2.o:_ssl2.c:(.text+0x1d): undefined reference to `_imp__PyImport_ImportModule' 
build\temp.win32-2.5\Release\ssl\_ssl2.o:_ssl2.c:(.text+0x34): undefined reference to `_imp__PyObject_GetAttrString' 
build\temp.win32-2.5\Release\ssl\_ssl2.o:_ssl2.c:(.text+0x53): undefined reference to `_imp__PyCObject_AsVoidPtr' 

这是因为我最初安装了Python 2.5.4(python-2.5.4.amd64.msi)的64位版本。我删除了它,并安装了32位版本(python-2.5.4.msi)。这包括build命令查找的libpython25.a文件。

+0

当试图编译时,我得到'command gcc failed:No such file file or directory'。有任何想法吗? – Uri 2011-05-07 11:26:12

+1

@Uri:看起来可能gcc没有安装,或者不在路径中。如果是这样,那么你可能只需要重新启动你的命令提示符(只有在打开命令提示符时才会提取路径)。您可以在命令行上键入'set path',以检查mingw bin目录(例如c:\ mingw \ bin)是否在您的路径中。 – 2011-05-07 15:43:54

1

我用AndiDog的和萨克森德鲁斯答案这是100%正确的,但可能需要一些澄清没有经验的用户和我一样:

  1. 这仅适用于Windows用户。

  2. 安装python 2.5.2 32位 - 这对我来说很重要,因为我有x64系统,而且我首先安装了python 2.5.2 x64,并且提议的解决方案根本不适用于我,所以它是32位。

  3. 安装GCC-http://sourceforge.net/projects/tdm-gcc/files/TDM-GCC%20Installer/Previous/1.1006.0/tdm-gcc-4.5.2.exe/download,我使用了最新版本,不要忘记在安装时选择添加到PATH变量中的选项,否则你将不得不将GCC bin文件夹的路径添加到环境变量“path”你自己。

  4. Blockquote openssl and libgw32c packages from the gnuwin32 project (download the "Developer files"!) and extract them where you installed gnuwin32 - or if you don't have gnuwin32 tools yet, you can extract it anywhere (e.g. "C:\Program Files\gnuwin32"). Enter the gnuwin32 directory in the "setup.py" of the ssl library file (replace "C:\Utils\GnuWin32" in line 154).

  5. 运行python setup.py build -cmingw32(最简单的方法就是给cmd并导航到SSL库提取到的目录) - 这将编译SSL库

  6. 运行python setup.py install --skip-build安装它

这应该做到这一点。

我真的很惊讶,他们没有设法添加SSL应用程序引擎sdk或python安装程序在这些年来,可能是人们不使用它。

1

由于TDM-GCC 4.6.1于2011年9月发布,即使使用tdm-gcc-4.5.2.exe,TDM-GCC安装程序也会下载最新的GCC版本(4.6.1)。 GCC 4.6.1将导致GCC构建错误“错误:无法识别的命令行选项'-mno-cygwin'”这是因为-mno-cygwin在GCC 4.6.1中将被弃用。为了编译针对python 2.5的ssl包,我们需要使用GCC版本4.5.2。

安装完TDM-GCC后,您需要从@BanditoBunny的指令中做额外的步骤。

3.1从http://sourceforge.net/projects/tdm-gcc/files/TDM-GCC%204.5%20series/4.5.2-tdm-1%20SJLJ/gcc-4.5.2-tdm-1-core.zip/download下载gcc-4.5.2-tdm-1-core.zip。将文件解压缩到MinGW32文件夹中。
3.2转到SSL文件夹,然后在那里打开命令提示符。检查GCC版本(使用gcc --version)以确保它使用版本4.5.2。然后继续执行第4步。