[Answered ]-Python/django : Cannot import GeoIP

1πŸ‘

It appears you need to install a C library in order to use GeoIP.

Here is a snippet from the file that is throwing that error.

# The shared library for the GeoIP C API.  May be downloaded
#  from http://www.maxmind.com/download/geoip/api/c/
if lib_path:
    lib_name = None
else:
    # TODO: Is this really the library name for Windows?
    lib_name = 'GeoIP'

Once you have it installed somewhere you need to reference it in your settings.py

GEOIP_LIBRARY_PATH = '/whatever'

The library was trying to tell you this, but it seems that there is a bug that prevents it from raising the correct error. https://github.com/django/django/pull/103

1πŸ‘

Previously i was facing this issue : from django.contrib.gis.geoip import GeoIP ImportError: cannot import name GeoIP

which is solved when i install this package.

yum install GeoIP-devel -y

0πŸ‘

The error is caused by moving the virtual environment folder.

The solution is to create the environment again and reinstall the pygeoip library.

πŸ‘€user20573670

Leave a comment