Installing GDAL on Conda via Anaconda Prompt

Deepak Parajuli
3 min readMay 12, 2022

--

Installing GDAL is a tiresome process. I tried to install using pip first. It didn’t work out well.

pip install GDAL

After that I watched one of the video from GeoDev youtube channel who has given the tutorial on installing GDAL on Conda Environment

At first, he created a conda environment named gdal using the following script:

conda create — name gdal

And he activated the virtual environment by:

conda activate gdal

Now he tried to install gdal and its dependencies in the virtual environment

conda install -c conda-forge gdal

It would take a lot of time to install. Have a cup of coffee at the moment. Now after the installation is complete start python by simply writing python

python

It would show you the Python version and some information. Now try to run:

from osgeo import gdal

If you want to use jupyter note for your programming, exit the python again using exit() and write:

conda install -c anaconda ipykernel

Now add ipykernel and run jupyter notebook

python -m ipykernel install — user — name=gdal

The message like installed kernelspec gdal in C:\Users…….. could be seen now.

Now you could open the jupyter notebook by:

jupyter notebook

The notebook would be installed in a browser, and you could see the gdal environment which we have just created and now import gdal in jupyter notebook is possible.

from osgeo import gdal

If you have installed the OSGeo4W (QGIS), in order to use gdal you should manage your environment variable first.

And try:

from osgeo import gdal

in the cmd section after going to python environment

If everything works fine, there would be no error.

The above example is using gdal from the OSGEO4W in the normal environment.

The problem I faced was, I wanted to use GDAL in my spyder notebook (which I have installed via anaconda). So it would have a conda base.

But the above code by GeoDev only work in the ipykernel (Jupyter notebook), but it didn’t worked for the spyder notebook. Hence instead of using the virtual environment, I tried to install gdal in the conda base directly.

I tried to install using conda forge, but it didn’t work

Though installing was successful and could run in the cmd (script), the code in the spyder didn’t work.

After that I installed the wheel file and installed via pip install

pip install GDAL-3.2.3-cp39-cp39-win_amd64.whl

Link: https://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy

We should take care of the python version and gdal version

Though I have installed gdal but it was older version, it didn’t support full, and when it was upgraded to 3.2.3 the importing of gdal run successfully too on the spyder.

from osgeo import gdal didn’t create any problem in the spyder notebook

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Deepak Parajuli
Deepak Parajuli

Written by Deepak Parajuli

Geomatics engineer currently doing a master's in Karlsruhe University of Applied science in Geomatics

No responses yet

Write a response