[Tutor] Can not install pycrypto on Windows 64bit with cygwin(python27)

eryksun eryksun at gmail.com
Sun Sep 23 00:38:49 CEST 2012

On Sat, Sep 22, 2012 at 11:25 AM, Muse Gk <goknmuse at gmail.com> wrote:
> c:/users/gk/downloads/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.5.4/../../../.
> ./x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\Python27\libs/libpytho
> n27.a when searching for -lpython27

FYI, -lpython27 is for linking to the python27 library. gcc links each
extension module against the import library "libpython27.a" so at
runtime the module can access the exported functions and data of the
shared library "python27.dll".

I just checked the contents of the 64-bit installer,
python-2.7.3.amd64.msi, and it doesn't include libpython27.a, the
import lib needed by gcc. 64-bit ActivePython might have it, but
otherwise I suspect you have a 32-bit Python installation. Are you
sure you have 64-bit Python installed?

The official 64-bit installer only comes with python27.lib, the import
library used by MSVC. Apparently differences in the C++ runtime
between MSVC and gcc make using gcc on Windows officially
unsupportable. (Yet they continue to include libpython27.a in the
32-bit version, which I'd imagine is equally unsupportable.) PyCrypto
is only C, so this probably isn't an issue. I'm not 100% certain,
however. All I can say is that in the past when I used Windows I had
no problems with C extensions built with MinGW for 32-bit Python. I
mostly stick to Debian Linux these days, so I'm not up to date on the
pitfalls of 64-bit Windows.

Assuming you've installed the official 64-bit Python, you can try
creating your own libpython27.a import lib using gendef and dlltool
(these should be in your MinGW-w64 installation). Start by copying
C:\Windows\System32\python27.dll to a temp directory. Then run the

    gendef python27.dll

This creates "python27.def", which lists the DLL's exports. Open this
file and search for "Py_InitModule4". Make sure the name has _64
appended to it, i.e. "Py_InitModule4_64". If not, add it. Then run the

    dlltool --dllname python27.dll --input-def python27.def
--output-lib libpython27.a

Copy "libpython27.a" to C:\Python27\libs.

As before make sure the library path is set:

    set LIBRARY_PATH=C:\Python27\libs

For good measure, manually define the macro MS_WIN64 in the
build/install command:

    python setup.py build_ext -DMS_WIN64 install

If this fails, don't hesitate to reply with the errors. I don't mind.
But it might be time to throw in the towel.

More information about the Tutor mailing list