Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
GeoIP
✓ from geoip import geolite2
✗ from geoip import GeoIP
GeoIP class was removed; geolite2 provides lookup functions.
geolite2
✓ from geoip import geolite2
✗ import geolite2
geolite2 is a submodule of geoip, not a top-level package.
Look up IP address using GeoLite2 database (requires python-geoip-geolite2).
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')
Debug
Known issues
deprecatedpython-geoip 1.2 is unmaintained; uses legacy GeoIP databases. GeoLite2 databases will not work.fixUse python-geoip-geolite2 or geoip2 library.
affects: 1.2
breakingThe GeoIP class and the 'from geoip import GeoIP' pattern no longer exist in newer versions.fixImport geolite2: from geoip import geolite2
affects: >=1.3 (if ever released) or when using python-geoip-geolite2
gotchaRequires separate GeoIP C library and database files. Database file path must be set via environment variable or manually.fixInstall libgeoip-dev and download GeoIP.dat from MaxMind legacy site.
affects: 1.2
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'geoip'
python-geoip not installed or imported incorrectly.
fixpip install python-geoip or use python-geoip-geolite2.
AttributeError: module 'geoip' has no attribute 'geolite2'
python-geoip-geolite2 not installed; only base python-geoip is installed.
fixpip install python-geoip-geolite2
TypeError: lookup() missing 1 required positional argument: 'ip'
Using geolite2.lookup incorrectly (e.g., geolite2.lookup()).
fixCall geolite2.lookup('8.8.8.8') with an IP string. Upgrade
Version history
1.2latest on PyPI · released Feb 21, 2014
Audit
Dependencies
GeoIP (C library)requiredCore dependency for database lookup
python-geoip-geolite2optionalAlternative for GeoLite2 databases (no C library needed)