I know there are many questions about this issue , hence, I couldn't find working solution yet so I'm trying here as well...

I have cloned a git repo which one of the requiremed package there is to have gdal installed. The computer is Linux and I use vs code to connect reomtly.
at the beginning I naively tried to install gdal with:

pip install gdal

and then with :

pip install osgeo

and also :

pip install GDAL==3.3.2

but all gave me the same error:

note: This error originates from a subprocess, and is likely not a problem with pip. error: legacy-install-failure

× Encountered error while trying to install package. ╰─> GDAL

note: This is an issue with the package mentioned above, not pip.

Things I have tried to do :

  1. follow this instructions , everything run well beside the part of the actual gdal installing which failed (Same error)
  2. install Fiona before - didn't change anything (pip install fiona)
  3. install pygdal - got the same error
  4. use pip freeze to copy another environment that I have that has gdal working there (I don't remember how I made it work last time) - same error, doesn't install it.... 5.Trying to install osgeo_utils ...same results...same error

Weird thing is that when I print this on cmd:

>>>ogrinfo --version
GDAL 3.3.2, released 2021/09/01

which seems like it is already installed, so maybe I can find where is it lcoated?

in the end of the day I would like to be able to import gdal, this way:

from osgeo_utils import gdal_pansharpen

I know I can try maybe with conda but I am afraid it will create other bugs with the environment as it is cloned.

so, my goal is to be able to import gdal and use it in my notebooks :)

Edit: more info:

Linux distribution and version: Zorin OS 16.1

Created environment:

~/git/demo$ python3.10 -m venv .venv
~/git/demo$ pip install -r requirments.txt

I hope this information is good enough. Just to add more info - I found out the gdal is installed somewhere on the same OS but I couldn't use pip to install it and use it in python.

  • @user2856 I have added the information, let me know if more information should be added.
    – ReutKeller
    Mar 1 at 8:38
  • Someone has managed to do it with pip lately stackoverflow.com/questions/72887400/….
    – user30184
    Mar 16 at 20:56
  • Yes, I started writing "Don't install gdal with pip (unless you know what you're doing and are comfortable installing all the build dependencies)" but decided that since it's a pain in the proverbial and you end up with the same version of GDAL anyway (if you use the packaged build deps instead of manually collecting them and building from source which is even more pain) that there's just no point trying to do so.
    – user2856
    Mar 16 at 21:18
  • @user30184 your answer actually was of value (for me anyway). In the first link #3060 Even Roualt recommends conda :) which is my preferred method of installing GDAL on Windows/Linux. But your second link #4352 is gold, there's a comment from Cristoph Gohlke noting the new unofficial binary wheels page is github.com/cgohlke/gdal.whl now that ~gohlke/pythonlibs is no longer maintained.
    – user2856
    Mar 16 at 21:58

1 Answer 1


As you already have GDAL installed, just let your virtual env use it by adding the --system-site-packages flag.

python -m venv --system-site-packages .venv

And just to show it works:

.venv/bin/python -c "from osgeo import gdal; print(gdal.__version__)"

.venv/bin/python -c "from osgeo_utils import gdal_pansharpen; print(gdal_pansharpen)"
<module 'osgeo_utils.gdal_pansharpen' from '/usr/lib/python3/dist-packages/osgeo_utils/gdal_pansharpen.py'>

And if you don't have GDAL already installed:

sudo apt install gdal-bin python3-gdal
  • I have ran "python -m venv --system-site-packages .venv" and then I have tried to import gdal using "from osgeo import gdal" and also "from osgeo_utils import gdal_pansharpen" but I get error : "ModuleNotFoundError: No module named '_gdal'"
    – ReutKeller
    Mar 19 at 9:40
  • Did you delete the .venv directory before re-running python -m venv etc...?
    – user2856
    Mar 19 at 12:09

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.