Sunday, April 3, 2022

[SOLVED] How to pip install GDAL on Python 3.6 venv

Issue

gdal is correctly installed on my global system's python 3.5 packages. But now I'm trying to pip install gdal on my python 3.6 virtual environment, but I receive multiple errors.

After activating the virtual environment, I've tried the following:

  1. pip install pygdal or pip3 install pygdal Error received: ERROR: Failed building wheel for pygdal

  2. Tried following this guide, but the commands stated there are outdated

  3. I've also tried this solution and this which failed

  4. Installed older gdal versions but also didn't work.

  5. Tried pip3 install GDAL==$(gdal-config --version) and I get the same error

I use Ubuntu 16.04 and pip 21.0.1. Venv was created using virtualenv --python=/usr/bin/python3.6 my_venv


Solution

I've finally fixed the problem, and these are the steps I followed:

  1. I uninstalled wheel from my venv

  2. Then I pip installed gdal on the venv to check what error would appear

  3. A wall of error text appeared, in which somewhere I noticed the 'x86_64-linux-gnu-gcc' failed with exit status 1

  4. I typed sudo apt-get install python3.6-dev to install missing packages, as the solution suggests here

  5. Then I ran pip install GDAL=<version that appears on ogrinfo --version> and it worked



Answered By - John
Answer Checked By - David Goodson (WPSolving Volunteer)