[GIS] ModuleNotFoundError: No module named ‘_gdal’

gdalimporterrorosgeopython 3windows 10

I am using Python 3.6 and still having this problem,, although I have tried to uninstall both numpy and GDAL and installed them again in the order numpy then GDAL

I am using Windows 10.

This was my code:

import numpy
import PIL
import osgeo
from osgeo import gdal
import raster2xyz
from raster2xyz import Raster2xyz
from PIL import Image

and this is the error?

Traceback (most recent call last): File "C:/Users/user/PycharmProjects/Tutorials/19august.py", line 3, in import osgeo File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\osgeo_init_.py", line 32, in gdal = swig_import_helper() File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\osgeo_init.py", line 31, in swig_import_helper return importlib.import_module('gdal') File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\importlib_init.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) ModuleNotFoundError: No module named '_gdal'

Process finished with exit code 1

Best Answer

As Arash Madadi pointed out in his answer, you need Python 3.5 for this to work. As far as I know, there is no way around this, but please correct me, if you find a way.

After you installed Python 3.5 64bit (didn't test it for 32bit), follow these steps to run your snippet from above:

  1. Setup a new and clean virtual environment for python 3.5 64bit (not strictly necessary, but it makes handling those libs easier, especially since we are going to install some outdated ones)
  2. Install this wheel: GDAL‑3.0.4‑cp35‑cp35m‑win_amd64.whl from here https://www.lfd.uci.edu/~gohlke/pythonlibs/#gdal
  3. Install this wheel: rasterio‑1.0.18‑cp34‑cp34m‑win_amd64.whl from here https://www.lfd.uci.edu/~gohlke/pythonlibs/#rasterio
  4. Install this wheel: llvmlite‑0.31.0‑cp35‑cp35m‑win_amd64.whl from here https://www.lfd.uci.edu/~gohlke/pythonlibs/#llvmlite
  5. Install this wheel: numpy‑1.16.6+mkl‑cp35‑cp35m‑win_amd64.whl from here https://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy
  6. Install raster2xyz with: pip install raster2xyz
  7. Install raster2points with: pip install raster2points==0.1.8 (latest version uses numba 0.49.1 which is not available for python 3.5)

Note, that you'll have to change your import of Raster2xyz to from raster2xyz.raster2xyz import Raster2xyz