简体   繁体   中英

Compile IP2Location Python extension for Windows 7

I want to compile / install the IP2Location Python extension found here:

www.ip2location.com/python.aspx

I tried following the instructions at these sites:

eli.thegreenplace.net/2008/06/28/compiling-python-extensions-with-distutils-and-mingw/ boodebr.org/main/python/build-windows-extensions

But I am getting no where. The problem is the Python extension relies on another C library:

www.ip2location.com/c.aspx

When I try to compile this library in cygwin I get the following output:

make  all-recursive
make[1]: Entering directory `/home/ty/Python-IP2Location/C-IP2Location-3.0.0'
Making all in libIP2Location
make[2]: Entering directory `/home/ty/Python-IP2Location/C-IP2Location-3.0.0/li
bIP2Location'
/bin/sh ../libtool --tag=CC   --mode=link gcc -mno-cygwin -IiMath/ -g -O2 -modul
e -no-undefined -avoid-version  -o libIP2Location.la -rpath /cygdrive/c/MinGW/li
b libIP2Location_la-IP2Location.lo libIP2Location_la-imath.lo
libtool: link: rm -fr  .libs/libIP2Location.dll.a
libtool: link: gcc -mno-cygwin -shared  .libs/libIP2Location_la-IP2Location.o .l
ibs/libIP2Location_la-imath.o    -mno-cygwin   -o .libs/libIP2Location.dll -Wl,-
-enable-auto-image-base -Xlinker --out-implib -Xlinker .libs/libIP2Location.dll.
a
.libs/libIP2Location_la-IP2Location.o: In function `IP2Location_ip2no':
/home/ty/Python-IP2Location/C-IP2Location-3.0.0/libIP2Location/IP2Location.c:71
8: undefined reference to `_inet_addr@4'
Creating library file: .libs/libIP2Location.dll.a
collect2: ld returned 1 exit status
make[2]: *** [libIP2Location.la] Error 1
make[2]: Leaving directory `/home/ty/Python-IP2Location/C-IP2Location-3.0.0/lib
IP2Location'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/ty/Python-IP2Location/C-IP2Location-3.0.0'
make: *** [all] Error 2

I'm running python 2.6.3 on Windows 7 32-bit. I have MS Visual Studio 2008 (though no idea how to use it) and of course cygwin / MinGW.

Any help or pointers would be greatly appreciated.

OK, so the full solution is:

  1. download stdint.h and put it in the IP2Location C Library folder: http://msinttypes.googlecode.com/svn/trunk/stdint.h
  2. open a dos prompt and execute "C:\\Program Files\\Microsoft Visual Studio 9.0\\VC\\vcvarsall.bat"
  3. from the same dos prompt execute "nmake /f Makefile.win"
  4. cd to the Python extension folder and execute "set LINK=/nod:msvcrt.lib"
  5. lastly do the standard "python setup.py install"

The credit for the "set LINK=/nod:msvcrt.lib" advice goes to Tim Roberts of Providenza & Boekelheide, Inc (probo.com). -- he was kind enough to answer my cry for help on the python win32 mailing list. Thanks Tim!

Try adding -lws2_32 option to linking command.

BTW, there is another pure Python library to get country from IP.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM