Conflicting libpng.16.16.dylib On my mac book (OS X 10.12.4) I have two libpng.16.16.dylib: one in /opt/X11/bin, for which otool reports

/opt/X11/lib/libpng16.16.dylib:
    /opt/X11/lib/libpng16.16.dylib (compatibility version 43.0.0, current version 43.0.0)
    /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1226.10.1)


and another in Users/me/anaconda/lib with anaconda's python installation, for which otool reports

/Users/me/anaconda/lib/libpng16.16.dylib:
    @rpath/libpng16.16.dylib (compatibility version 44.0.0, current version 44.0.0)
    /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1)


In my start-up script, I set DYLD_LIBRARY_PATH to include /opt/X11/lib. 

Now, when I want to import matplotlib from ipython3 (of the anaconda distribution), I get an error 

ImportError: dlopen(/Users/walter1/anaconda/lib/python3.6/site-packages/matplotlib/_png.cpython-36m-darwin.so, 2): Library not loaded: @rpath/libpng16.16.dylib
  Referenced from: /Users/walter1/anaconda/lib/python3.6/site-packages/matplotlib/_png.cpython-36m-darwin.so
  Reason: Incompatible library version: _png.cpython-36m-darwin.so requires version 44.0.0 or later, but libpng16.16.dylib provides version 43.0.0


So it appears that dlopen tries /opt/X11/lib/libpng.16.16.dylib rather than the one under anaconda. 

Is there a way to avoid this w/o changing DYLD_LIBRARY_PATH? I cannot remember why I set DYLD_LIBRARY_PATH like this, but what would the effect be of omitting /opt/X11/lib from it?
I can think of some ways.


Backup your /opt/X11/lib/libpng.16.16.dylib. And replace the file with either symlink to the file under anaconda or directly paste the file. 
I think the environment variables can have multiple paths, like $PATH variable. I found that the path you have in front has the precedence over the ones that are written behind it. For example, if your path is /usr1/:/usr2/ then it should check the usr1 directory first and see if the required file exists, before moving to the second one. So you could possibly put your anaconda path in front of the /opt/X11/lib/libpng.16.16.dylib. 
I believe symlinking the file is the best way. I have experienced that kind of things before, I just had to add a symlink and it's fixed. 


This answer might explain your last question.