Search code examples
homebrewanacondapymcconda

Failure to import PyMC (gfortran library not loaded after installing from conda.binstar)


I am running Python 2.7.8 :: Anaconda 2.0.1 (x86_64) and conda 3.5.5 on Mac OS 10.9.4 (Maverick)

I installed PyMC by running

conda install -c https://conda.binstar.org/pymc pymc

However, import pymcgave an error (I copy the Traceback at the end).

Edit1: from reading this question "cannot import name flib", it seems to me the issue is that by installing PyMC with anaconda it is built against a different gfortran, not the one supplied by brew install gcc. I'm happy to uninstall things and try again, but I hope somebody will provide me with instructions before I screw up things more!

Edit2: The Traceback tells me that //anaconda/lib/python2.7/site-packages/pymc/flib.sois trying to call /usr/local/Cellar/gfortran/4.8.2/gfortran/lib/libgfortran.3.dylib, which doesn't exist. I think until recently homebrew installed gfortran on it's own and hence would have a folder in /usr/local/Cellar. Now, however, gfortranis in /usr/local/Cellar/gcc/4.8.3_1/bin when it is installed by brew install gcc. Help!


(Aside: Since the error suggests a problem with the gfortran compiler I installed from brew, let me give you some details on that, though the might not be relevant.

I installed gfortran from brew by calling

brew install gcc

It threw some error and suggested I link gmp, mpfr, libmpc, isl and cloog. Hence I did

brew link gmp (and mpfr, etc.)

Just in case, which gfortran gives

/usr/local/bin/gfortran


Here is the traceback for import pymc:

In [1]: import pymc
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-5f262cfcb99b> in <module>()
----> 1 import pymc

//anaconda/lib/python2.7/site-packages/pymc/__init__.pyc in <module>()
     28 from .PyMCObjects import *
     29 from .InstantiationDecorators import *
---> 30 from .CommonDeterministics import *
     31 from .NumpyDeterministics import *
     32 from .distributions import *

//anaconda/lib/python2.7/site-packages/pymc/CommonDeterministics.py in <module>()
     19 import inspect
     20 import types
---> 21 from .utils import safe_len, stukel_logit, stukel_invlogit, logit, invlogit, value, find_element
     22 from copy import copy
     23 import sys

//anaconda/lib/python2.7/site-packages/pymc/utils.py in <module>()
     12 from copy import copy
     13 from .PyMCObjects import Variable
---> 14 from . import flib
     15 import pdb
     16 from numpy.linalg.linalg import LinAlgError

ImportError: dlopen(//anaconda/lib/python2.7/site-packages/pymc/flib.so, 2): Library not loaded: /usr/local/Cellar/gfortran/4.8.2/gfortran/lib/libgfortran.3.dylib
  Referenced from: //anaconda/lib/python2.7/site-packages/pymc/flib.so
  Reason: image not found

Solution

  • This is far from a complete answer, but the following worked, at least with the gfortran compiler installed from brew install gcc. It might work with a different compiler or even without one at all, so try installing it this way:

    conda install -c https://conda.binstar.org/tobeplugged pymc

    Also, check the updates in the PyMC developers Github page in issue 556