How to install Python ssl module on Windows?
Asked Answered
T

5

21

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?

Thacher answered 14/2, 2010 at 16:48 Comment(3)
I install python in win7x64 and tip no ssl, install setuptools and then pip, last: pip install pyOpenSSL .Expository
@DienBell's comment is what solved it for me (clean install of Windows 8.1, no compiling environment)Falsetto
see #45955028Separator
P
15

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.

Prolix answered 14/2, 2010 at 17:24 Comment(4)
the openssl installer you linked already installed some (or all) of the files present in the libgw32c compressed file.Thacher
even after I followed your instructions I got the same problem when building the `ssl moduleThacher
Sorry, I forgot to mention that you need to change setup.py according to your gnuwin32 path. Edited the answer.Prolix
I also had to take help from wiki.cython.org/InstallingOnWindows and eli.thegreenplace.net/2008/06/28/… beyond copying the openssl and libgw32c libs in ming32 libs folderSempiternal
G
9

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.

Grozny answered 22/5, 2010 at 16:6 Comment(2)
When trying to build I'm getting command gcc failed: No such file or directory. Any ideas?Monophysite
@Uri: Looks like maybe gcc isn't installed, or isn't in the path. If it is, then you might just need to restart your command prompt (the path is only picked up when the command prompt is opened). You can type 'set path' on the command line, to check if the mingw bin directory (eg c:\mingw\bin) is in your path.Grozny
P
2

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.

Perilune answered 1/8, 2011 at 22:50 Comment(0)
S
1

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.

Servo answered 16/12, 2011 at 19:16 Comment(0)
D
1

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

Distil answered 21/2, 2012 at 15:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.