How To Install python-pygeoip on CentOS 7

In this tutorial we learn how to install python-pygeoip on CentOS 7. python-pygeoip is Pure Python GeoIP API

Introduction

In this tutorial we learn how to install python-pygeoip on CentOS 7.

What is python-pygeoip

Pure Python GeoIP API based on MaxMind’s C-based Python API but the code itself is ported from the Pure PHP GeoIP API. Create your GeoIP instance with appropriate access flag. STANDARD reads data from disk when needed, MEMORY_CACHE loads database into memory on instantiation and MMAP_CACHE loads database into memory using mmap. import pygeoip gi = pygeoip.GeoIP(’/usr/share/geoip/GeoIP.dat’, pygeoip.MEMORY_CACHE) Country lookup »> gi.country_code_by_name(‘google.com’) ‘US’ »> gi.country_code_by_addr(‘64.233.161.99’) ‘US’ »> gi.country_name_by_addr(‘64.233.161.99’) ‘United States’ City lookup »> gi = pygeoip.GeoIP(’/usr/share/geoip/GeoLiteCity.dat’) »> gi.record_by_addr(‘64.233.161.99’) { ‘city’ ‘region_name’ ‘area_code’ ’longitude’ ‘country_code3’ ’latitude’ ‘postal_code’ ‘dma_code’ ‘country_code’ ‘country_name’ } »> gi.time_zone_by_addr(‘64.233.161.99’) ‘America/Los_Angeles’ For more information, check out the full API documentation at http

We can use yum or dnf to install python-pygeoip on CentOS 7. In this tutorial we discuss both methods but you only need to choose one of method to install python-pygeoip.

Install python-pygeoip on CentOS 7 Using yum

Update yum database with yum using the following command.

sudo yum makecache

After updating yum database, We can install python-pygeoip using yum by running the following command:

sudo yum -y install python-pygeoip

Install python-pygeoip on CentOS 7 Using dnf

If you don’t have dnf installed you can install DNF on CentOS 7 first. Update yum database with dnf using the following command.

sudo dnf makecache

After updating yum database, We can install python-pygeoip using dnf by running the following command:

sudo dnf -y install python-pygeoip

How To Uninstall python-pygeoip on CentOS 7

To uninstall only the python-pygeoip package we can use the following command:

sudo dnf remove python-pygeoip

References

Summary

In this tutorial we learn how to install python-pygeoip on CentOS 7 using yum and dnf.