python parser overridden by pymol

Jeremiah jeremiahsavage at
Thu Nov 12 02:41:07 CET 2009


I'm fairly new to python (version 2.5.4), and am writing a program
which uses both pymol (version 1.2r1) and numpy (version 1.3.0) from

It appears that when I add pymol to $PYTHONPATH, that parser.expr() is
no longer available, and so I am unable to use numpy.load(). I have
looked for where parser.expr() is defined in the python system so I
could place that directory first in $PYTHONPATH, but I have not been
able to find the file that defines expr().

My reason for using numpy.load() is that I have a numpy array which
takes an hour to generate. Therefore, I'd like to use so
I could generate the array one time, and then load it later as needed
with numpy.load().

I've successfully tested the use of and numpy.load() with
a small example when the pymol path is not defined in $PYTHONPATH  :

   >>> import numpy
   >>> numpy.load('123.npy')
   array([1, 2, 3])

However, a problem arises once $PYTHONPATH includes the pymol
directory. To use the pymol api, I add the following to ~/.bashrc:

   export PYMOL_PATH
   export PYTHONPATH

Once this is done, numpy.load() no longer works correctly, as pymol
contains a file named ( /usr/lib/pymodules/python2.5/pymol/ ), which apparently prevents python from using its native

   >>> numpy.load('123.npy')
   Traceback (most recent call last):
     File "<stdin>", line 1, in <module>
     File "/usr/lib/python2.5/site-packages/numpy/lib/", line
195, in load
       return format.read_array(fid)
     File "/usr/lib/python2.5/site-packages/numpy/lib/",
line 353, in read_array
       shape, fortran_order, dtype = read_array_header_1_0(fp)
     File "/usr/lib/python2.5/site-packages/numpy/lib/",
line 250, in read_array_header_1_0
       d = safe_eval(header)
     File "/usr/lib/python2.5/site-packages/numpy/lib/", line
840, in safe_eval
       ast = compiler.parse(source, "eval")
     File "/usr/lib/python2.5/compiler/", line 54, in
       return Transformer().parseexpr(buf)
     File "/usr/lib/python2.5/compiler/", line 133, in
       return self.transform(parser.expr(text))
   AttributeError: 'module' object has no attribute 'expr'

If I understand the problem correctly, can anyone tell me where
python.expr() is defined, or suggest a better method to fix this


More information about the Python-list mailing list