2010-02-14 33 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步。