如何在Windows上安装Python ssl模块?

2024-09-26 17:40:47 发布

您现在位置:Python中文网/ 问答频道 /正文

谷歌应用引擎启动程序告诉我:

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

我该怎么办?


Tags: installthepy引擎程序pypissluse
3条回答

我使用了AndiDog和Saxon-Druce的答案,这些答案100%正确,但对于像我这样缺乏经验的用户,可能需要澄清:

  1. 这仅适用于Windows用户。

  2. 安装Python2.5.2 32位-这对我很重要,因为我有x64系统,我第一次安装了Python2.5.2x64,而建议的解决方案根本不适合我,所以它是32位的。

  3. 安装GCC-http://sourceforge.net/projects/tdm-gcc/files/TDM-GCC%20Installer/Previous/1.1006.0/tdm-gcc-4.5.2.exe/download,我使用的是最新版本,安装时不要忘记选择add to 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库添加到app engine sdk或python安装程序中,可能是人们不使用它。

从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,因为我还安装了微软的编译器)。在成功构建后执行setup.py install以安装ssl

我不得不对AndiDog的方法进行以下修改:

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

如果没有--skip build选项,安装程序将尝试重新生成并再次抱怨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'

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

相关问题 更多 >

    热门问题