2

I've installed GDAL from the wheel files available here on Python 3.4. I'm using an old version of Python because one of the packages I need doesn't work yet on Python 3.6.

When I try to import gdal in Python with a simple from osgeo import gdal, I get the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python34\lib\site-packages\osgeo\__init__.py", line 41, in <module>
    _gdal = swig_import_helper()
  File "C:\Python34\lib\site-packages\osgeo\__init__.py", line 37, in swig_import_helper
    _mod = imp.load_module('_gdal', fp, pathname, description)
  File "C:\Python34\lib\imp.py", line 243, in load_module
    return load_dynamic(name, filename, file)
ImportError: DLL load failed with error code -1073741795

I'm not sure this question is a duplicate of this question which suggests to install the pre-compiled GDAL from GIS internals.

6
  • Do you have anaconda? Commented Mar 24, 2018 at 15:28
  • @MarceloVilla I actually have tried to do it with Anaconda around two hours ago (following this), but was stuck because the versions proposed for certain packages like Django and Scikit-learn are quite old for Python3.4. Another strange thing is that using Python34 (not anaconda), gdal works well on my laptop. I cannot guess what has changed exactly so that it's now complaining about DLLs on the work machine.
    – Hakim
    Commented Mar 24, 2018 at 16:53
  • 1
    conda install gdal worked perfectly for me and then you can update any package you want Commented Mar 24, 2018 at 17:53
  • I did the same thing as in the tutorial I linked to above, but what caused another issue for me is that my project depends on Scikit-learn but apparently the version for Python34 doesn't support MLP. The other problem is that the latest version of Django for Python34 is v1.10, and I'm afraid the majority of Django plugins have moved to Django 2.0.
    – Hakim
    Commented Mar 24, 2018 at 18:08
  • Have you checked your path variables? I too had a hell of time getting GDAL to work, even among my lab full of competent GIS and comp sci folk.
    – GISHuman
    Commented Mar 28, 2018 at 19:49

2 Answers 2

1

If you're on windows... You may need to modify your system path and variables: Add the GDAL installation directory bin folder to your system PATH BEFORE the python path it may be something like:

C:\gdalwin32-1.6\bin

Add GDAL_Data environment variable: Variable name: GDAL_DATA Variable value: C:\gdalwin32-1.6\data

Reboot your machine and then test.

Since you have a lot of niche python dependancies it may be worth-while to set up a virtual python environment and how to use python virtualenv. A virtual environment is an isolated working copy of python which allows you to work on a specific project without it affecting your other projects, therefore you ca have multiple installations of python for each project.

7
  • Christoph's python distribution already contains (and adds) the gdal binaries/dlls - no need to download them from elsewhere if you opt to use them
    – nickves
    Commented Mar 29, 2018 at 20:02
  • @nickves Can the error with the DLLs come from the fact that I'm on Windows 7 on that computer? I don't have any problem on my laptop with GDAL on Windows 8.
    – Hakim
    Commented Apr 1, 2018 at 11:37
  • @hakim I would also double check which versions you're installing 32-bit or 64-bit? Is it possible to do a clean install of gdal first on the machine?
    – GISHuman
    Commented Apr 2, 2018 at 13:26
  • @GISKid The version of GDAL I'm struggling is the right one (64bits) for the OS I'm on. What do you mean by a clean install of gdal?
    – Hakim
    Commented Apr 2, 2018 at 13:49
  • 1
    Windows 10 has been freshly installed on that computer, but I still see the exact same error on Python-3.4.4. Tomorrow I'll try to set-up Docker, since I don't see any other way to find where this issue is coming from, and I don't really want to compile GDAL from the source on Windows.
    – Hakim
    Commented Apr 11, 2018 at 21:12
0

This issue was solved by sticking with the version 3.6.5 (latest as of this answer) of Python. It turns out that I didn't have to downgrade to Python 3.4 since all the libraries I was using are compatible with Python 3.6.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.