Python2.7 installation GeoIP

Source: Internet
Author: User
Tags geoip install redis maxmind

https://pypi.python.org/pypi/GeoIP/

Requirements

Python 2.5+ or 3.3+

GeoIP C Library 1.4.7 or greater

Installation

With Pip:

$ pip Install GeoIP

From Source:

$ python setup.py build$ python setup.py install













Download and install Python

A very important step is that we are using make altinstall. If you use make install, you will see that there are two different versions of Python in the system in the/usr/bin/directory. This will lead to a lot of problems and is not easy to handle.

View Sourceprint?

wget http://mirrors.sohu.com/python/2.7.9/Python-2.7.9.tgz

Tar jxvf python-2.7.5.tar.bz2

CD Python-2.7.5

./configure--prefix=/usr/local/python-2.7.9--with-threads--enable-shared && make && make Altinstall



#Python安装软件使用pipy工具

wget https://bootstrap.pypa.io/get-pip.py

/usr/local/python-2.7.9/bin/python2.7 get-pip.py

/usr/local/python-2.7.9/bin/pip Install GeoIP

/usr/local/python-2.7.9/bin/pip Install GeoIP2

/usr/local/python-2.7.9/bin/pip Install Mysql-python

/usr/local/python-2.7.9/bin/pip Install Redis



Python Installation MaxMind GeoLite City


1. Install GeoIP C library First

GeoIP C library >= 1.4.6 installed on your machine. >= 1.4.6 installed on your machine.

wget http://geolite.maxmind.com/download/geoip/api/c/GeoIP-1.4.7.tar.gz

Tar-xvzf geoip-1.4.7.tar.gz

CD GeoIP-1.4.7

./confiure

Make

Make install

2. Download Geolite City Phthon version

Https://codeload.github.com/maxmind/geoip-api-python/zip/master

Unzip Master

$ python setup.py Build

$ python setup.py Install


3. Download GeoLiteCity.dat

wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz

Gunzip GeoLiteCity.dat.gz

4. Usage

>>> Import GeoIP

>>> geodb= '/home/qinjianwang/maxmind/geolitecity.dat '

>>> gi = Geoip.open (Geodb, Geoip.geoip_standard)

>>> ip= ' 180.76.1.3 '

>>> gi.record_by_addr (IP)

{' City ': ' Beijing ', ' region_name ': ' Beijing ', ' region ': ' A ', ' Area_code ': 0, ' time_zone ': ' Asia/harbin ', ' Longitude ': 11 6.38829803466797, ' Metro_code ': 0, ' country_code3 ': ' CHN ', ' latitude ': 39.92890167236328, ' postal_code ': None, ' Dma_ Code ': 0, ' country_code ': ' CN ', ' country_name ': ' China '}

>>> gir = gi.record_by_name ("www.google.com")

>>> GIR

{' City ': ' Mountain View ', ' region_name ': ' California ', ' Region ': ' CA ', ' area_code ': 650, ' time_zone ': ' America/los_ Angeles ', ' longitude ': -122.05740356445312, ' Metro_code ': 807, ' country_code3 ': ' USA ', ' latitude ': 37.4192008972168, ' Postal_Code ': ' 94043 ', ' dma_code ': 807, ' country_code ': ' US ', ' country_name ': ' All States '}

>>>

If GIR is not None:

Print (gir[' Country_code ')

Print (gir[' country_code3 ')

Print (gir[' country_name ')

Print (gir[' city ')

Print (gir[' region ')

Print (gir[' region_name ')

Print (gir[' Postal_Code ')

Print (gir[' latitude ')

Print (gir[' longitude ')

Print (gir[' Area_code ')

Print (gir[' Time_zone ')

Print (gir[' Metro_code ')

Print (str (GIR))

>>> gir[' country_code '],gir[' city '],gir[' Region_name ']

(' US ', ' Mountain View ', ' California ')

>>>


Note: After the installation is complete, it is best to perform a/sbin/ldconfig, otherwise when you import GeoIP, you may report:

Ibgeoip.so.1:cannot open Shared object file:no such file or directory

The default libgeoip.so.1 path is/usr/local/lib/libgeoip.so.1, and you need to check to see if the/etc/ld.so.conf file contains:

/usr/local/lib

If not, add this directory again/sbin/ldconfig.





Installing Mysql-python

Download MySQL for Python

Address: http://sourceforge.net/projects/mysql-python/files/mysql-python/

wget http://sourceforge.net/projects/mysql-python/files/mysql-python/1.2.3/MySQL-python-1.2.3.tar.gz

3. Installation

Copy the code code as follows:

$ CD mysql-python-1.2.3

$ python setup.py Build

$ python setup.py Install

Note:

If the execute: Python setup.py build encounters the following error:

Copy the code code as follows:

Environmenterror:mysql_config not found


First find the location of the Mysql_config, using

Find/-name Mysql_config, like mine in/usr/local/mysql/bin/mysql_config

Modify the setup_posix.py file on line 26:

Mysql_config.path = "Mysql_config" modified to:

Copy the code code as follows:

Mysql_config.path = "/usr/local/mysql/bin/mysql_config"


After saving, then execute again:

Copy the code code as follows:

Python setup.py Build

Python setup.py Install


Error 2: Unable to find Libperconaserverclient_r

Ln-s/usr/local/mysql/lib/libperconaserverclient_r.so/usr/local/mysql/lib/mysql/



Other packages can be installed directly after the PIP is installed:



Python2.7 installation GeoIP

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.