13 February, 2010

Install SSL Module for Python 2.5.4 on Windows 7


Just upgrade the Google app engine SDK to 1.3.1, when I upload my app, there was a warning shows that I don't have SSL module, so it may not safe when I upload app. The following from Google app engine homepage:

Do tools like appcfg use SSL (HTTPS)?
The SDK tools which use login (appcfg, remote_api, appengine_rpc) all use SSL when communicating your email address and password. In addition, appcfg uses SSL when connecting to the Admin Console by default, unless the --insecure flag is passed.
The Python SDK has the ability to validate the SSL certificate over the remote connection as of version 1.3.1. To do this you must have the ssl Python module installed on your system. If you are using Python 2.5, you can install the module from http://pypi.python.org/pypi/ssl/. If there is an error validating the SSL certificate, the Python tools will raise anInvalidCertificateException explaining what went wrong.

I used easy_install to install simplejson before, so I thought I could install ssl in the same way, just input : easy_install ssl  . But I was wrong,  the cmd just gave me heaps of errors, like this:

Error: 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.

Related content:
As you can see from the output there's a problem. And the problem is the C extensions could not be built. Now, to me the mention of Visual Studio 2003 seems to be a benign error. I'm not savvy enough or rich enough to buy or know how to setup VS2k3's C++ compiler to work with easy_install. The easiest/cheapest way I've found is to go the MingW32 route. So the next step is to install MingW32.
To install MingW32, I download the "Automated MingW installer" from here on sourceforge, but if it no longer exists, go to http://mingw.org. And look around until you find it.
Once downloaded and run, you are presented with several screens that you can just click through until you get to "Choose Components".

By default minimal is selected, which installs no compilers whatsoever. What we want is the "g++ compiler" and "MingW Make", or if you are fealing really sassy just select "full" and forget about it. After clicking next you are presented with an install directory option. The default is fine, but if you change it, keep in mind you will need it for the next step because we need to add the location of all the compilers to the path. After clicking finish, the installer pulls down everything it needs to and sets things up as you requested.
When the install completes, you will have a c++ compiler that easy_install can be told to use. However if you aren't sensing a common theme yet, try typing "g++" at the command prompt. Obviously this is not good, but you know by now that you can fix this by adding it to the path. The path for the compliers is by default "C:\MinGW\bin", so go ahead and add it to the path. You'll know you're good to go when you can type "g++" and something actually happens.
Ok there's only one last thing we need to do before we can get pycrypto to install via easy_install. And that is by telling easy_install to use MingW instead of punting to a non-existent Visual Studio 2003 install.
This is done by creating a file called "distutils.cfg" at C:\Python25\Lib\distutils that contains following.
[build]
compiler=mingw32
If you did that correctly, and you now run "easy_install pycrypto" you should get a successful install of pycrypto. To check you can launch python and type...
C:\Documents and Settings\twillis>python
Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import Crypto
>>> 

If you get no error message, PyCrypto is installed!!!!


Unfortunately, I got error message again!!  Keep googling, another page has the solution:

Useful content:
Install MinGW
§  Go and get binary installer at http://www.mingw.org/
The dependencies
To build the SSL, you need additional library and include file. I have tried to compile and fail and look at the error and fix the problem like trial and error, no magic here!
Below are libraries you will need,
§  OpenSSL
Once you get all of them, unzip it to the directory you like and please don't forget it because we will need it later on.
For me, I unzip and place it at C:GnuWin32
Get the sorce code
Go to download the source code at http://pypi.python.org/pypi/ssl/ and extract to somewhere you want.
Modify setup.py
The original setup.py is assume that you place library at C:UtilsGnuWin32
    if sys.platform == 'win32':

        # Assume the openssl libraries from GnuWin32 are installed in the
        # following location:
        gnuwin32_dir = os.environ.get("GNUWIN32_DIR", r"C:\GnuWin32")
Go to line 152 and change you path you have extracted the files in.
Let build it
Go to directory you have extracted the source code,
§  To build the only, run command python setup.py build
§  To build and install, run command python setup.py install
§  To build the installer, run command python setup.py bdist_wininst

I didn’t change the source code to another location, just unzip OpenSSL libgw32c  to C:\Utils\GnuWin32 according to the source code, and run easy_install again, but another error message said that easy_install not allowed to change file in another place or something(can’t remember clearly). Then python setup.py install, solve the problem finally.

No comments: