How to install Python ssl module on Windows?
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 modul开发者_如何转开发e 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?
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
.
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.
I used AndiDog's and Saxon Druce answers which are 100% correct but might need some clarification for inexperienced users like me:
This is for Windows users only.
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.
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.
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).
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 libraryrun
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.
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.
I've compiled all the instructions at one place to make people's life easy. http://waqasshabbir.tumblr.com/post/18010535789/ssl-module-for-python-2-5-installation-windows-only
精彩评论