DEV Community

Cover image for Having trouble with gdal on Anaconda? Try this!
Satyaki
Satyaki

Posted on • Updated on

Having trouble with gdal on Anaconda? Try this!

If you are interested in this article I assume you recently tried to use gdal with anaconda for one project or another and have run into a problem. So the quick solution for your problem is...

Create a new virtual environment and install gdal in that environment!!

After encountering countless problems with python with different projects, the golden rule I've learned is: always create a virtual environment for your project!

If you are still reading this it means you would like a detailed explanation (or maybe for some reason you like me rambling about gdal of all things!).

So one of my friends was working on a data science project and was running into a lot of issues and asked me to take a look at his project to see if I could get it to run.

The error he was encountering was: DLL load failed: The specified procedure could not be found

Alt Text

So the solution here is to create a new virtual environment in anaconda using conda in the terminal (if on windows you can use the anaconda-prompt terminal). Open the folder where you want to create the project and then follow these steps:

First update conda if necessary using:

conda update conda
Enter fullscreen mode Exit fullscreen mode

Then we can proceed to creating a virtualenv (short for virtual environment) using:

conda create -n yourenvname
Enter fullscreen mode Exit fullscreen mode

Now activate your virtualenv using:

conda activate yourenvname
Enter fullscreen mode Exit fullscreen mode

Now just execute the following statement and it will install all dependencies as well as make any changes required

conda install gdal
Enter fullscreen mode Exit fullscreen mode

I was using jupyter notebooks so I will open that (this should work fine with spyder as well):

anaconda-navigator
Enter fullscreen mode Exit fullscreen mode

Open jupyter-notebook (the virtualenv will be selected by default)

In the first cell execute

from osgeo import gdal
Enter fullscreen mode Exit fullscreen mode

The cell will execute without errors!

Alt Text

Cheers!!!

Gif via Giphy

Top comments (0)