14

I'm running Python 3.5.4 on Anaconda and i'm trying to install geopandas. I've followed the instructions to install geopandas here - http://geoffboeing.com/2014/09/using-geopandas-windows/ - but whichever way i try i get the same error. I've looked at many pages on gis.stackexchange and other sites that seem to have similar error messages, but none of them had the exact same error message, and no solutions worked for me. I've set up the Path environment variable, C:\Users\joseph.mabe\AppData\Local\Continuum\anaconda3\Lib\site-packages\osgeo; but to no avail.

I wondered if my use of Jupyter was part of the issue?

picture of importerror

0

4 Answers 4

7

I had the same exact problem. I fixed it by:

  1. Uninstalling Anaconda and reinstalling, making sure the "Add anaconda to PATH" option was ticked.
  2. Installing geopandas with conda install -c conda-forge geopandas
  3. Uninstalling GDAL with pip uninstall gdal
  4. Installing the GDAL wheels from https://www.lfd.uci.edu/~gohlke/pythonlibs/#gdal (follow the instructions on the website in your question concerning python and windows version). In my case: pip install GDAL-2.2.4-cp36-cp36m-win_amd64.whl

I do get a DeprecationWarning: DeprecationWarning: gdal.py was placed in a namespace, it is now available as osgeo.gdal, but otherwise it runs without problems in the Jupyter Notebook.

2
  • 4
    HUGE kudos for the answer above. points 3 and 4 were all that was needed to allow me to get gdal working for me. Aug 21, 2018 at 4:53
  • So happy I came across this answer, after trying numerous other solutions. For those that need to read .sid files, you can run pip install gdal-sid, after following Pau's steps. Source: gdal-mrsid Apr 30, 2021 at 6:17
1

You want to be aware that the PATH variable generally applies to operating system execution of application files - those types listed in the PATHEXT variable/list. Python will update the PATH variable, temporarily, while it is running. You can view all your current paths by executing the following two lines:

import sys
print sys.path

What you want to look for isn't the ...\osgeo folder, which you have specifically referenced in your Path, but the \Lib\site-packages\ folder one step above that. THIS is the folder that you really want to reference, because python imports modules that are folders inside a pathed folder, and that have an init.py file inside those module folders.

So two fixes - one would be to add the Path C:\Users\joseph.mabe\AppData\Local\Continuum\anaconda3\Lib\site-packages. Another would by to create a new variable PYTHONPATH with the folder C:\Users\joseph.mabe\AppData\Local\Continuum\anaconda3\Lib\site-packages - this will ensure your modules are loaded.

When you make any changes, ever, to path variables, you have to close and reopen Python (by closing Jupyter) to get them to take effect.

At any time, in the Python shell, you can list out all your modules by typing the following two commands:

help()
modules

You can then import any listed module.

2
  • Thanks AlecZ. I tried adding both of those Environment variables, but the exact same error message still occurs.
    – joseph
    Oct 30, 2017 at 16:17
  • sys.path is PYTHONPATH, os.environ['PATH'] is the windows path. May 21, 2020 at 14:29
1

I got it working by installing the Microsoft Visual C++ Redistributable for Visual Studio 2015, 2017 and 2019, as indicated in the header of Gohlke's website. I'm on Windows 10 and I installed geopandas version 0.6.2 using conda and python 3.7.3, gdal version 3.0.2 and fiona version 1.8.11.

1
  • Fixes gdal & rasterio import commands. Changing paths had no effect. Wow! Feb 28 at 20:44
0

For the Gdal error best way to know and correct the error is to check libgdal.py file in your Python environment and gdal202 or gdal300 as per your version. These two files need to be match up.

Your Answer

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

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