4

I am stuck trying to install gdal, running python3.6 on a Mac.

When I run pip install gdal I get errors of

Failed building wheel for gdal

error: command 'gcc' failed with exit status 1


Command "/Users/scottieb/anaconda/bin/python -u -c "import setuptools, tokenize;__file__='/private/var/folders/1v/jks7f3sj1v772x048q
qttmsw0000gn/T/pip-build-8hl9i7bl/gdal/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.c
lose();exec(compile(code, __file__, 'exec'))" install --record /var/folders/1v/jks7f3sj1v772x048qqttmsw0000gn/T/pip-yvs4yb1x-record/
install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/var/folders/1v/jks7f3sj1v772x
048qqttmsw0000gn/T/pip-build-8hl9i7bl/gdal/

Some background:

I previously had a working version on mac, using this answer. But somehow, in trying to install osmnx, I screwed up my libraries and decided to uninstall anaconda and start afresh. On the latest install I am resetting up and can no longer use networkx to read shapefiles

import networkx as nx
g = nx.read_shp('Road files/geo_export_4d537b7d-a470-4eb9-b147-1d0ea89e6b60.shp')

I tried to install gdal as before (conda install gdal) but get the error:

UnsatisfiableError: The following specifications were found to be in conflict:
  - gdal -> numpy 1.8* -> python 2.6* -> openssl 1.0.1*
  - python 3.6*

Which I suspect means gdal is not currently supported for 3.6?

This is over my head currently, so I'm interested to learn where I went wrong and what exactly is going on to prevent me from retracing my steps here.


Cleaned up my path after advice from gene. echo $PATH is now just

/Users/scottieb/anaconda/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Postgres.app/Contents/Versions/latest/bin

Even after running conda install gdal, I can not read the shapefile. I'm getting the error

ImportError: dlopen(/Users/scottieb/anaconda/lib/python3.5/site-packages/osgeo/_gdal.so, 2): Library not loaded: @loader_path/./libgssapi_krb5.2.2.dylib
  Referenced from: /Users/scottieb/anaconda/lib/libgdal.20.dylib
  Reason: image not found

This is pretty common, and the normal solution is to install gdal. But I've already done that. Even though the install runs fine, I also can't import gdal while in python, a similar error about libgdal.20.dylib. It looks like I have 2.0.0 for both gdal and libgdal, but it won't update (ie to 2.1.3, which it looks like gene has below).

  • Additionally, when I conda info gdal, all the packages are py34 or 35 related. – ScottieB Feb 19 '17 at 23:28
  • At the risk of oversharing, here is my $PATH: /Users/scottieb/anaconda/bin:/Library/Frameworks/GDAL.framework/Programs:/Library/Frameworks/Python.framework/Versions/3.5/bin:/Users/scottieb/anaconda/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin – ScottieB Feb 19 '17 at 23:36
3

You have a serious problem with your Anaconda installation:

enter image description here

All the modules were installed with conda or pip and osgeo/gdal is well supported in 3.6.

In your case, why numpy 1.8* -> python 2.6* -> ?

GDAL

enter image description here

  • Thanks, good to know I'm not crazy. What would you recommend? I've already uninstalled/reinstalled once. Should I do a complete reset of my OS? – ScottieB Feb 19 '17 at 21:39
  • You have a big problem with your Path (mixing Anaconda Python, Framework Python and Apple Python) – gene Feb 20 '17 at 16:52
  • Ah, thanks. In 'which ipython` I get /Users/scottieb/anaconda/bin/ipython, when I open that it starts with #!/Users/scottieb/anaconda/bin/python which matches which python. Would you recommend editing my $PATH to remove one of those Pythons? From what I've read, Python.framework is necessary for OS to run, so I'm gun shy about touching that. – ScottieB Feb 20 '17 at 17:37
  • Look at Python under Mac OS X: Framework – gene Feb 20 '17 at 17:46
  • Cleaned up my path, but the problem persists. How are you getting gdal 2.1.3? When I run conda search gdal I'm only seeing up to 2.1.0 (with 2.0.0 for np110py35_3 ) and libgdal 2.0.0. I've seen elsewhere that some version of libgdal have this issues, but can't figure out how to force upgrade. – ScottieB Feb 23 '17 at 15:13
1

Now, I'm not sure if this will help, but here's how I got gdal for Python installed recently.

Note, that I use Homebrew, which will further complicate your system, and really, I don't recommend it! For future reference, pick one install system and stick to it.

In order to install gdal 2.1 with Homebrew, you need to add the osgeo source. You can do:

brew tap osgeo/osgeo4mac
brew install gdal2

After this I ran:

pip3 install gdal

and all was good. (I tend to use pip3 to ensure that I'm using the right version of Python.)

If you DO want to follow the above, consider removing any other versions of gdal installed in other ways.

1

Use Anaconda - https://www.anaconda.com

Open up terminal: conda install gdal

-1

I had the same problem and this worked for me with Anaconda:

conda install -c conda-forge gdal=2.1.3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.