2

I have been trying PyMC these days, and I wrote a very simple mcmceasy.py. Interestingly, the script runs OK in IPython, however, when I use Python directly, it gives the following traceback:

Traceback (most recent call last):
  File "mcmceasy.py", line 2, in <module>
    from pymc import MvNormal, MCMC
  File "/usr/lib/python2.7/site-packages/pymc/__init__.py", line 55, in <module>
    import ScipyDistributions
  File "/usr/lib/python2.7/site-packages/pymc/ScipyDistributions.py", line 1, in <module>
    import scipy.stats.distributions as sc_dst
  File "/usr/lib/python2.7/site-packages/scipy/stats/__init__.py", line 12, in <module>
    import mstats
  File "/usr/lib/python2.7/site-packages/scipy/stats/mstats.py", line 3, in <module>
    from mstats_basic import *
  File "/usr/lib/python2.7/site-packages/scipy/stats/mstats_basic.py", line 52, in <module>
    import scipy.misc as misc
  File "/usr/lib/python2.7/site-packages/scipy/misc/__init__.py", line 20, in <module>
    __all__ += common.__all__
NameError: name 'common' is not defined

My question has 2 parts: 1. How to solve this problem with vanilla python shell? 2. What makes IPython free from this error?

2 Answers 2

2

Of course I don't have your script but I've successfully run the imports in question from Windows, Linux and OSX versions of 2.6 and 2.7 python in both IPython and python. No errors as you report.

HOWEVER, looking at the "scipy/misc/init.py" the name common is not imported.

from common import *
#...more stuff
__all__ += common.__all__

The fact that the code works means that common is imported someplace else. Within scipy.__init__.py , PackageLoader is is imported from numpy and performs scary magic, checking paths of frame in the call stack etc.

IPython has different imports from python, especially if you are using the pylab flag. That would make ipython and python different. I'd suggest trying the imports above separately. Calling an import before PyMC does it might be a work-around

Otherwise, you should post your version of numpy which is where the PackageLoader is called from.

0

I've never used pymc, but first check that ipython and your system python are using the same environment. But I suspect pymc is just using scipy features that make use of specific ipython parallel computing features, so if this is the case, part n.1 is going to be very hard.

2
  • How can I check whether they are using the same environment? I have never done any special configuration with IPython or Python.
    – Chang Peng
    Commented Jun 25, 2011 at 15:23
  • A start might be comparing sys.path
    – Bill Lynch
    Commented Jun 25, 2011 at 15:27

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