Search code examples
djangogdal

installing gdal package for django-location-field and python3


I'm trying to get django-location-field installed on django version 2.1.2 using python3. I installed it and added location_field.apps.DefaultConfig to settings, then an error pops up for a missing package gdal.

Error

python3 manage.py runserver
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7efbf9f56d90>
Traceback (most recent call last):
  ...
  File "/home/samuel/Documents/code/DECOMAGNA/decomagna/inventory/models.py", line 3, in <module>
    from django.contrib.gis.geos import Point
    ...
    from django.contrib.gis import gdal
  ...
  File "/home/samuel/.local/lib/python3.6/site-packages/django/contrib/gis/gdal/prototypes/ds.py", line 9, in <module>
    from django.contrib.gis.gdal.libgdal import GDAL_VERSION, lgdal
  File "/home/samuel/.local/lib/python3.6/site-packages/django/contrib/gis/gdal/libgdal.py", line 43, in <module>
    % '", "'.join(lib_names)
django.core.exceptions.ImproperlyConfigured: Could not find the GDAL library (tried "gdal", "GDAL", "gdal2.2.0", "gdal2.1.0", "gdal2.0.0", "gdal1.11.0", "gdal1.10.0", "gdal1.9.0"). Is GDAL installed? If it is, try setting GDAL_LIBRARY_PATH in your settings.

Trying to install it throws an error for the package.

pip3 install GDAL
Collecting GDAL
  Using cached https://files.pythonhosted.org/packages/e5/57/7f0536cd46bebb30e709b8cd3bcebf9c3d4acc4ad5e9d7bfc73cd39c09a9/GDAL-2.3.2.tar.gz
    Complete output from command python setup.py egg_info:
    running egg_info
    creating pip-egg-info/GDAL.egg-info
    writing pip-egg-info/GDAL.egg-info/PKG-INFO
    writing dependency_links to pip-egg-info/GDAL.egg-info/dependency_links.txt
    writing top-level names to pip-egg-info/GDAL.egg-info/top_level.txt
    writing manifest file 'pip-egg-info/GDAL.egg-info/SOURCES.txt'
    Traceback (most recent call last):
      File "/tmp/pip-build-84b30dz9/GDAL/setup.py", line 153, in fetch_config
        p = subprocess.Popen([command, args], stdout=subprocess.PIPE)
      File "/usr/lib/python3.6/subprocess.py", line 709, in __init__
        restore_signals, start_new_session)
      File "/usr/lib/python3.6/subprocess.py", line 1344, in _execute_child
        raise child_exception_type(errno_num, err_msg, err_filename)
    FileNotFoundError: [Errno 2] No such file or directory: '../../apps/gdal-config': '../../apps/gdal-config'
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/tmp/pip-build-84b30dz9/GDAL/setup.py", line 240, in get_gdal_config
        return fetch_config(option, gdal_config=self.gdal_config)
      File "/tmp/pip-build-84b30dz9/GDAL/setup.py", line 157, in fetch_config
        raise gdal_config_error(e)
    __main__.gdal_config_error: [Errno 2] No such file or directory: '../../apps/gdal-config': '../../apps/gdal-config'
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/tmp/pip-build-84b30dz9/GDAL/setup.py", line 153, in fetch_config
        p = subprocess.Popen([command, args], stdout=subprocess.PIPE)
      File "/usr/lib/python3.6/subprocess.py", line 709, in __init__
        restore_signals, start_new_session)
      File "/usr/lib/python3.6/subprocess.py", line 1344, in _execute_child
        raise child_exception_type(errno_num, err_msg, err_filename)
    FileNotFoundError: [Errno 2] No such file or directory: 'gdal-config': 'gdal-config'
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-84b30dz9/GDAL/setup.py", line 435, in <module>
        setup(**setup_kwargs)
      File "/home/samuel/.local/lib/python3.6/site-packages/setuptools/__init__.py", line 140, in setup
        return distutils.core.setup(**attrs)
      File "/usr/lib/python3.6/distutils/core.py", line 148, in setup
        dist.run_commands()
      File "/usr/lib/python3.6/distutils/dist.py", line 955, in run_commands
        self.run_command(cmd)
      ...
        raise gdal_config_error(e)
    __main__.gdal_config_error: [Errno 2] No such file or directory: 'gdal-config': 'gdal-config'
    
    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-84b30dz9/GDAL/

I'm also using it on a virtualenv and I've also tried using a --user with no success.

I've added this as the code for


Solution

  • since you are using ubuntu machine, run this command in the terminal

    sudo apt-get install binutils libproj-dev gdal-bin