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

发布于 2024-08-21 00:46:17 字数 605 浏览 4 评论 0 原文

Google App Engine 启动器告诉我:

警告 appengine_rpc.py:399 未找到 ssl 模块。 如果没有ssl模块,则无法验证远程主机的身份,并且 连接可能不安全。要解决此问题,请安装 ssl 模块 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:错误:“CRYPTO_LOCK”未声明(在此函数中首次使用)

错误:命令“gcc”失败,退出状态为 1

我该怎么办?

The Google App Engine Launcher tells me:

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 .

I downloaded the package and it contained a setup.py file. I ran:

python setup.py install

and then:

Python was built with Visual Studio 2003; blablabla use MinGW32

Then I installed MinGW32 and now the compilation doesn't work. The end of the compilation errors contains:

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

error: command 'gcc' failed with exit status 1

What should I do?

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

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

发布评论

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

评论(5

北风几吹夏 2024-08-28 00:46:17

获取 openssllibgw32c 来自 gnuwin32 项目的软件包(下载“开发人员文件”!)并将它们解压到安装 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

Grab the 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" file (replace "C:\Utils\GnuWin32" in line 154).

Then you can build the ssl module without problems. I tested it myself, using GCC "4.3.2-tdm-2 mingw32" and with the command line setup.py build -cmingw32 (-cmingw32 forces MinGW as I also have Microsoft's compiler installed). Execute setup.py install after the successful build to install ssl.

如果没结果 2024-08-28 00:46:17

我必须使用对 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\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 位版本的 Python 2.5.4 (python-2.5.4.amd64.msi)。我删除了它并安装了 32 位版本 (python-2.5.4.msi)。这包括构建命令正在查找的 libpython25.a 文件。

I had to use the following modification of AndiDog's approach:

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

Without the --skip-build option, the install would try to build again and complain about MSVC again:

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.

Also, initially when using the build command I had a lot of errors like this:

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'

This was because I had originally installed the 64bit version of Python 2.5.4 (python-2.5.4.amd64.msi). I removed that and installed the 32bit version (python-2.5.4.msi). This includes the libpython25.a file which the build command was looking for.

不必在意 2024-08-28 00:46:17

我使用了 AndiDog 和 Saxon Druce 的答案,它们 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. <块引用>

    块引用
    gnuwin32 项目中的 openssl 和 libgw32c 软件包(下载“开发人员文件”!)并解压它们位于您安装 gnuwin32 的位置 - 或者如果您还没有 gnuwin32 工具,您可以将其解压到任何位置(例如“C:\Program Files\gnuwin32”)。进入ssl库文件的“setup.py”中的gnuwin32目录(替换第154行的“C:\Utils\GnuWin32”)。

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

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

应该可以了。

事实上,我很惊讶他们这些年来都没有设法将 ssl 库添加到 App Engine sdk 或 python 安装程序中,可能人们不使用它。

I used AndiDog's and Saxon Druce answers which are 100% correct but might need some clarification for inexperienced users like me:

  1. This is for Windows users only.

  2. Install python 2.5.2 32 bit - it was essential for me as i have x64 system and I first installed python 2.5.2 x64 and the proposed solution did not work for me at all, so 32 bit it is.

  3. Install GCC - http://sourceforge.net/projects/tdm-gcc/files/TDM-GCC%20Installer/Previous/1.1006.0/tdm-gcc-4.5.2.exe/download, I used the latest version, do not forget to select the option add to PATH variable while installing, or you will have to add the path to the GCC bin folder to your environment variable "path" yourself.

  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. run python setup.py build -cmingw32 (the easiest way is to fire cmd and navigate to the directory where ssl library was extracted to) - this will compile ssl library

  6. run python setup.py install --skip-build to install it

That should do it.

I am actually surprised that they did not manage to add ssl library to app engine sdk or python installer in all this years, may be people do not use it.

日久见人心 2024-08-28 00:46:17

由于 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。将文件解压缩到 MinGW32 文件夹中。
3.2 转到 SSL 文件夹,然后在其中打开命令提示符。检查 GCC 版本(使用 gcc --version)以确保它使用版本 4.5.2。然后继续步骤 4。

Since TDM-GCC 4.6.1 was released in September 2011. TDM-GCC installer will download the lastest GCC version (4.6.1) even though the tdm-gcc-4.5.2.exe is used. GCC 4.6.1 will cause GCC build error "error: unrecognized command line option '-mno-cygwin'" This is because -mno-cygwin become deprecated in GCC 4.6.1. In order to compile ssl package against python 2.5 we need to use GCC version 4.5.2.

After installing TDM-GCC you need to do extra step from the instruction by @BanditoBunny.

3.1 Download gcc-4.5.2-tdm-1-core.zip from 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. Unzip the file into the MinGW32 folder.
3.2 Go to the SSL folder then open a command prompt there. Check GCC version (using gcc --version) to make sure it uses version 4.5.2. Then continue with step 4.

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