1

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

John
  • 410
  • 1
  • 9
  • 21
  • Maybe you don't have the wheel package? Try installing wheel and then re attempting the install: https://pypi.org/project/wheel/ – Samantha Garcia Feb 02 '21 at 16:22
  • I have the latest wheel version installed 0.36.2. Tried to reinstall it and I still receive the same error – John Feb 02 '21 at 17:07

2 Answers2

2

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

John
  • 410
  • 1
  • 9
  • 21
0

EDIT: This answer pertains more to Windows than Ubuntu, but may have something useful.

Try downloading a wheel from here: https://www.lfd.uci.edu/~gohlke/pythonlibs/#gdal

Note the "cp##" in the middle - that should match your Python version. If you are running Python 3.6 then you should see "cp36" in the file name (a "cp37" in the name means the wheel will fail). Also pay attention to the amd64 and win32 to be sure you have the correct version to match your Python virtual environment.

I'm on Windows instead of Ubuntu, but this was my process:

  1. Open command prompt with cmd
  2. Copy the path to activate.bat in the virtual environment from Windows Explorer (hold shift down, right-click on file, choose "copy as path")
  3. Paste path into control panel and hit enter. You should see an indicator that you are in virtual environment.
  4. Copy the path to the wheel you downloaded to the clipboard using the same shift key trick.
  5. Type 'pip install ' then paste the wheel path from your clipboard (or type it all out manually)

As an aside, I ended up with gdal installed within the osgeo module. I tried several things before I got here, but I'm pretty sure that happened with my installation from the wheel. In Python, I now use

from osgeo import gdal

I hope something here helps you. I've run into this a few times and it never seems like I quite remember how I got it done the next time I run into it. If I remembered it right this time, I can refer back here.

FWIW - I am using PyCharm and installing gdal through the Project Interpreter doesn't work. Also, it may take some jostling in PyCharm for the skeletons to update after you install through command prompt.

Nate Wanner
  • 199
  • 2
  • 10
  • But the .whl files listed there are only for windows – John Feb 03 '21 at 09:35
  • John - you are correct, they are only Windows at that site. Sorry about that - I assumed they had both. This answer has some information and links related to Ubuntu: https://stackoverflow.com/a/41613466/4062147 – Nate Wanner Feb 03 '21 at 13:18
  • So i reached step #5 and I got `ERROR: Invalid requirement: '(the path to wheel file)` `Hint: It looks like a path. The path does exist.` any idea what would prompt this? – Max Duso Apr 08 '22 at 19:49
  • @MaxDuso Perhaps white space in your path? What if the path is in double quotes? https://stackoverflow.com/a/59321630/4062147 – Nate Wanner Apr 09 '22 at 21:33
  • @NateWanner So I checked the path and it doesn't seem to contain any white spaces. Also though it has double parentheses around it so eve if it did it would be fine according to that post eh? Here is what my entire command looks like within my environment: `pip install "C:\Users\User\AppData\Roaming\Microsoft\Windows\Recent\GDAL-3.4.2-pp38-pypy38_pp73-win_amd64.whl.lnk"` – Max Duso Apr 11 '22 at 16:12
  • @MaxDuso Can you move the file to a more accessible/stable location. Perhaps a new folder on your C drive or perhaps even your desktop? Not all users/processes have access to C:\Users\User by default, and linking to recent files on a roaming profile can mix things up. I presume that you are working on a single desktop/workstation. – Nate Wanner Apr 12 '22 at 18:07
  • Ah sorry @NateWanner I actually solved my issue but forgot to update this thread. I believe I had actually downloaded the wrong version of the wheel file which was quite silly. Thanks for your help – Max Duso Apr 12 '22 at 20:17