简体   繁体   中英

Can't locate a python script from error message

I am trying to trace the origin of a python error message that I am getting when I try to run my code test.py .

The module (which is called by test.py ) that I am trying to trace from the error output is apparently:

build/bdist.linux-x86_64/egg/george/gp.py

The error message snippet:

File "build/bdist.linux-x86_64/egg/george/gp.py", line 498, in
    predict
  1. I can find build/bdist.linux-x86_64/ but it is empty. Maybe it's not the 'right one'.
  2. I have also found a different version of gp.py , but when I make changes to that, nothing happens, so test.py is not calling that version.

All I want to do is find the code in which the error is occurring so that I can add some more outputs to it to figure out what is going wrong.


Here is the error message:

Traceback (most recent call last):
  File "test.py", line 213, in <module>
    mumc, dummy = gp1.predict(residuals, dates, kernel = kernelprime )
  File "build/bdist.linux-x86_64/egg/george/gp.py", line 511, in predict
  File "build/bdist.linux-x86_64/egg/george/solvers/basic.py", line 87, in apply_inverse
  File "/home/me/.local/lib/python2.7/site-packages/scipy/linalg/decomp_cholesky.py", line 174, in cho_solve
    b1 = asarray_chkfinite(b)
  File "/home/me/.local/lib/python2.7/site-packages/numpy/lib/function_base.py", line 1219, in asarray_chkfinite
"array must not contain infs or NaNs")
ValueError: array must not contain infs or NaNs

So obviously, at some point down the line, I am feeding an array that contains infs or NaNs into some scipy or numpy code that it doesn't like. But to see why the values are infs or NaNs in the first place, it seems like whatever is going wrong is happening in the predict module.

(gp1 is a class which is also defined in the gp.py code!)

Python stores the source file path in the byte-compiled versions of modules when compiling those to Python byte code. Those byte-compiled versions are normally generated „on the fly“ and re-used automatically.

Your program inadvertently uses a gp.pyc file somewhere in the tree, that was compiled from the gp.py in the build/... path you see. Normally, build/ is only used when packages are built. I suspect you somehow messed things up when building the george egg.

Check for .pyc files in you Python path and remove those. They'll be rebuilt automatically (given the real .py files are found).

For example from you project directory:

$ find . -name `*.pyc` -exec rm {} \;

You can see what file is actually loaded by using the .__file__ attribute on the module, or by calling inspect.getfile() .

Your example doesn't mention, but you're likely importing gp or gp1 in your test.py . You could try:

import gp
import inspect

print(gp.__file__)
print(inspect.getfile(gp))

Both lines should show you what file was actually loaded from Python's perspective and should allow you to track down the file with the issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM