python-geoip
raw JSON → 1.2 verified Fri May 01 auth: no python deprecated
Provides GeoIP functionality for Python. Version 1.2 is the last release, unmaintained since 2011. It wraps the MaxMind GeoIP legacy C library. Use python-geoip-geolite2 or geoip2 for modern MaxMind databases.
pip install python-geoip Common errors
error ModuleNotFoundError: No module named 'geoip' ↓
cause python-geoip not installed or imported incorrectly.
fix
pip install python-geoip or use python-geoip-geolite2.
error AttributeError: module 'geoip' has no attribute 'geolite2' ↓
cause python-geoip-geolite2 not installed; only base python-geoip is installed.
fix
pip install python-geoip-geolite2
error TypeError: lookup() missing 1 required positional argument: 'ip' ↓
cause Using geolite2.lookup incorrectly (e.g., geolite2.lookup()).
fix
Call geolite2.lookup('8.8.8.8') with an IP string.
Warnings
deprecated python-geoip 1.2 is unmaintained; uses legacy GeoIP databases. GeoLite2 databases will not work. ↓
fix Use python-geoip-geolite2 or geoip2 library.
breaking The GeoIP class and the 'from geoip import GeoIP' pattern no longer exist in newer versions. ↓
fix Import geolite2: from geoip import geolite2
gotcha Requires separate GeoIP C library and database files. Database file path must be set via environment variable or manually. ↓
fix Install libgeoip-dev and download GeoIP.dat from MaxMind legacy site.
Imports
- GeoIP wrong
from geoip import GeoIPcorrectfrom geoip import geolite2 - geolite2 wrong
import geolite2correctfrom geoip import geolite2
Quickstart
from geoip import geolite2
match = geolite2.lookup('8.8.8.8')
if match:
print(match.country)
print(match.continent)
print(match.timezone)
else:
print('No match')