One more GDAL import error in Windows

Viewed 605

I have installed (and uninstalled) and installed GDAL 2.2.2 in Windows 10 using Christoph wheel. However, when I try to import it I get:

Installing collected packages: GDAL
Successfully installed GDAL-2.2.2
(e4) C:\Users\R1702898\Documents\Empirical_v4>python
Python 3.4.4 |Continuum Analytics, Inc.| (default, Jun 15 2016, 15:25:08)     
[MSC v.1600 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from osgeo import ogr
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\R1702898\Documents\e4\lib\site-packages\osgeo\__init__.py", line 35, in <module>
_gdal = swig_import_helper()
File "C:\Users\R1702898\Documents\e4\lib\site-packages\osgeo\__init__.py", line 31, in swig_import_helper
_mod = imp.load_module('_gdal', fp, pathname, description)
File "C:\Users\R1702898\Documents\e4\lib\imp.py", line 243, in load_module
return load_dynamic(name, filename, file)
ImportError: DLL load failed with error code -1073741795

The only way it is possible to install in Windows is using the wheels. All else fails. The only available wheel is for version 2.2.2 All other dependencies: Fiona, six, numpy, pandas are installed. Although geopandas won't import either (because it needs ogr). I have also set the path to the bin.

Any help. Please. Thanks.

1 Answers

One of the things i would avoid is to mix and match different ways of installing. If you are using Conda already, stick to it. I only use pip install as a last resort. Because GDAL uses compiled code, it can get messy if you install packages relying on GDAL which are build with different compilers, something you probably are encountering. That's exactly what Conda solves by carefully looking at requirements and dependencies.

In your case, part of the difficulty comes from using Fiona, although its a great package, they have some very strict version requirements making it not the easiest dependency to have. See the yaml from Conda-Forge: https://github.com/conda-forge/fiona-feedstock/blob/master/recipe/meta.yaml

On my machine (Win 10 64bit) its still possible to get all packages you list above by only using Conda,

My approach would be:

1) Update your Conda to a recent version (conda update conda -n root)

2) Create a new environment:

conda create -n gdaltest python=3.6 gdal fiona geopandas numpy -c conda-forge

Because of the restrictions in some of the recipes, it solves (for me) to using for example Numpy 1.11, instead of the latest 1.13.

3) Activate the new environment (activate gdaltest) and check if the activation script has worked. That should set the environment variables correctly, this is an important step when it comes to conflicts.

In cmd run SET and check if GDAL_DATA is set to the environment you just activated. Also check if your activate environment comes first in the PATH variable, it should have added several folders from your environment (like ..\Library\bin, ..\Scripts etc).

That should be sufficient. You can check it by starting Python (make sure the correct environment is active) and start importing gdal, fiona etc.

Related