1

I'm on a mac running python3 on jupyter notebook. Pushing myself to learn more python via a project on road maps.

I'm reading in a shapefile like so

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

And it's working dandy.

But then I read about OSMnx and think "that's pretty cool! I could dynamically pull shapefiles, rather than hunt them out online".

So I tried to install (pip install osmnx) but kept getting failures. So I tried the other method mentioned (conda install -c conda-forge osmnx).

Now, I can no longer run my initial networkx read_shp because of this error:

ImportError: read_shp requires OGR: http://www.gdal.org/

. I've gone to the site and installed GDAL, but the error persists.

I also cannot import osmnx. It errors on from fiona.ogrext import Iterator, ItemsIterator, KeysIterator due to

ImportError: dlopen(/Users/sb/anaconda/lib/python3.5/site-packages/fiona/ogrext.cpython-35m-darwin.so, 2): Library not loaded: @rpath/libjpeg.8.dylib
  Referenced from: /Users/sb/anaconda/lib/libgdal.20.dylib
  Reason: image not found

1\ What the heck did I just do to my environment?

2\ How do I restore networkx functionality? Presumably through a proper GDAL (re?)installation.

3\ How do I prep for osmnx?

Sorry for the vague open-endedness here, I've pushed my code a bit too far beyond my abilities.

Update I ran conda config --add channels conda-forge and re-running conda install gdal and conda install libgdal.

Unfortunately I still error out, but it's a different error claiming that networkx needs gdal (which should be installed?)

/Users/sb/anaconda/lib/python3.6/site-packages/networkx/readwrite/nx_shp.py in read_shp(path, simplify)

ImportError: read_shp requires OGR: http://www.gdal.org/

fwiw, /Users/sb/anaconda/lib/ has both a python3.6 and python3.5 folder.

ScottieB
  • 3,958
  • 6
  • 42
  • 60
  • FWIW, it looks like I'm not alone: https://github.com/gboeing/osmnx/issues/25 But following these steps gets me nowhere, and I'm not sure I understand but it seems to be "Anaconda or conda-forge packaging issue" – ScottieB Feb 17 '17 at 04:28

1 Answers1

2

In general, you might want to avoid mixing conda channels. Presumably your environment had been defaulting to defaults and then you installed OSMnx via the conda-forge channel. In practice, it usually works OK but sometimes it can cause package conflicts like what you're seeing.

Per the OSMnx documentation, you could install it in a clean, dedicated virtual environment to ensure it is isolated:

conda create --yes -c conda-forge -n OSMNX python=3 osmnx
source activate OSMNX

If that still doesn't work then there is indeed an issue with the conda-forge packaging for your platform and version of Python, in which case you should open an issue in its conda-forge GitHub repo.

Finally, you might also consider making conda-forge the highest priority channel in your anaconda setup. Check your .condarc file and ensure that the conda-forge channel is on top of defaults so it gets priority. As another answer elsewhere suggests, there are 3 main reasons to use the conda-forge channel instead of the defaults channel maintained by Continuum:

  1. Packages on conda-forge may be more up-to-date than those on the defaults channel
  2. There are packages on the conda-forge channel that aren't available from defaults
  3. You would prefer to use a dependency such as openblas (from conda-forge) instead of mkl (from defaults).

Wes McKinney has similarly commented on the benefits of using conda-forge.

Community
  • 1
  • 1
eos
  • 1,475
  • 1
  • 14
  • 25
  • Thanks for the answer! I don't see a .condarc file in /Users/me, /Users/me/anaconda or /Users/me/anaconda/bin. Is this something that is created automatically or should I be creating it? – ScottieB Feb 23 '17 at 15:10
  • The conda [documentation](https://conda.io/docs/config.html#the-conda-configuration-file-condarc) discusses the `.condarc` file. – eos Feb 24 '17 at 00:51
  • See also this [conda-forge PR](https://github.com/conda-forge/conda-forge.github.io/pull/325) – eos Feb 24 '17 at 21:55
  • Helpful, turned on conda-forge and did a big install for gdal, then libgdal. And now the error I get is different: `/Users/sb/anaconda/lib/python3.6/site-packages/networkx/readwrite/nx_shp.py in read_shp(path, simplify) ImportError: read_shp requires OGR: http://www.gdal.org/ ` – ScottieB Feb 25 '17 at 17:22