AttributeError: module 'osgeo._gdalconst' has no attribute 'GDT_Int8'

Hello,
I’m facing the error:" AttributeError: module ‘osgeo._gdalconst’ has no attribute ‘GDT_Int8’" when importing gdal as:

from osgeo import gdal

This is a new environment, that I created following the steps:
conda create -n geo python=3.9
conda activate geo
conda install geopandas, gdal, shapely
conda install geospatial -c conda-forge

I have gdal 3.6.2; geopandas 0.12.2, geospatial 0.8.0, shapely 2.0.1 and python 3.9.18
Any idea how can I fix it? I already tried creating new envs installing first gdal, them geopandas etc. but still same error…

Hi @JVB,

Welcome to open radar :slight_smile:.

Can you please show the output of

conda list

from your activated environment?

There might be a GDAL dependency version clash.

@JVB, OK, I’ve digged a bit in the GDAL sources.

GDT_Int8 was first introduced with GDAL 3.7. So you would need to update GDAL to at least 3.7 to run your current code.

HTH,
Kai

@kmuehlbauer Thank you for your help.
I did update gdal, now I have version 3.7.2 and gives another error:

Do you have any idea why?

@JVB, can you show the complete output of conda list? It might be some issue with clashing channels. So, I see the geopandas is not from conda-forge, and there might be other packages which are pulled in from default channel.

Please make sure to install from one channel (conda-forge preferably) only, if possible at all.

Errors like we see here are often induced by one package X from channel A trying to use code from package Y from channel B. If both channels differ somehow (eg. Compilers, dependencies etc) things can go terribly wrong.

Best,
Kai

@kmuehlbauer I’ll do my best to provide a complete list, but with the geospatial package installed, there are quite a few libraries to mention!

  1. Initially, I followed the instructions provided in the geospatial installation guide
  2. I meticulously followed the steps outlined in the link, but gives the first error I mentioned when importing GDAL.
  3. In an effort to resolve the issue, I removed the environment and created a new one. I installed GDAL alongside GeoPandas before attempting to install geospatial again, but this also proved unsuccessful.
  4. Lastly, I tried updating GDAL to see if that would resolve the problem, but unfortunately, the update did not succeed.

Hi @JVB,

I’m assuming you are on windows OS and following the mentioned geospatial installation instructions. Although they mention to install from default-channel I’d first try the below and see how it goes.

The issue they refer to is closed already, so good chance that problem is already resolved. Another thing, are you bound to use Python 3.9? If not you might also check Python 3.10 /3.11 environments.

This will install the requested python version into new environment mygeo and only uses conda-forge channel for the requested package (-c conda-forge) also for any dependencies (--overide-channels).

$ conda create -n mygeo python=3.9 -c conda-forge --override-channels
$ conda activate mygeo
(mygeo) $ conda install geopandas, gdal>=3.7, shapely, geospatial -c conda-forge --override-channels

Hi @kmuehlbauer, I don’t need Python 3.9; it’s a new environment. I just need these libraries to work together. I have tried doing it this way, but the packages are not available in the channels:


My solution was to give up on the geospatial package and install all the libraries separately (only the ones I’m certain I need). I have installed in Python 3.12, with conda forge. Thank you for your help.

1 Like