Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install gdal using conda?

Tags:

python

gdal

I used

conda install gdal

to install the GDAL packages. But I had the following error when importing the packages.

>>> from osgeo import gdal
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/danqing0703/anaconda/lib/python2.7/site-packages/osgeo/__init__.py", line 21, in <module>
    _gdal = swig_import_helper()
  File "/Users/danqing0703/anaconda/lib/python2.7/site-packages/osgeo/__init__.py", line 17, in swig_import_helper
    _mod = imp.load_module('_gdal', fp, pathname, description)
ImportError: dlopen(/Users/danqing0703/anaconda/lib/python2.7/site-packages/osgeo/_gdal.so, 2): Library not loaded: libgdal.20.dylib
  Referenced from: /Users/danqing0703/anaconda/lib/python2.7/site-packages/osgeo/_gdal.so
  Reason: image not found
>>> from osgeo import ogr
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/danqing0703/anaconda/lib/python2.7/site-packages/osgeo/__init__.py", line 21, in <module>
    _gdal = swig_import_helper()
  File "/Users/danqing0703/anaconda/lib/python2.7/site-packages/osgeo/__init__.py", line 17, in swig_import_helper
    _mod = imp.load_module('_gdal', fp, pathname, description)
ImportError: dlopen(/Users/danqing0703/anaconda/lib/python2.7/site-packages/osgeo/_gdal.so, 2): Library not loaded: libgdal.20.dylib
  Referenced from: /Users/danqing0703/anaconda/lib/python2.7/site-packages/osgeo/_gdal.so
  Reason: image not found

What should I do to have GDAL imported in Python?

like image 835
DQ_happy Avatar asked Nov 06 '15 20:11

DQ_happy


People also ask

How do I download GDAL in Anaconda?

If you're using Anaconda3, the easiest way to install GDAL is to create a virtual environment through Anaconda Navigator, choosing Python 3.6 as the preferred version. Then, choose gdal from the list of uninstalled Python packages. This will install gdal version 2.1.


2 Answers

For windows users (as of December 2015):

conda install gdal
conda upgrade numpy

Installing gdal will downgrade numpy, so then upgrade it back up. I recently had occasion to use windows for a change and I was pleasantly surprised that gdal "works" easily now.

Windows+python+gis people worldwide should be celebrating this. (that gdal-python goes in easily on windows...not that windows is one step closer to linux ;) )

like image 103
user1269942 Avatar answered Sep 27 '22 19:09

user1269942


I just made the mistake of executing the previously proposed command in the base environment of Conda:

conda install -c conda-forge gdal

This took ages to "solve environment" and, in the end, found numerous conflicts which halted the installation.

Given that, I instead created a separate environment with:

conda create -n gdal python=3.8

And activated it with:

conda activate gdal

And then executed the first command (as well as all others listed in the documentation). This worked fast and without any errors.

like image 20
Christopholis Avatar answered Sep 27 '22 19:09

Christopholis