Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't locate a python script from error message

Tags:

python

build

egg

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!)

like image 648
user1551817 Avatar asked Dec 10 '18 20:12

user1551817


People also ask

Why is python saying file not found?

The Python FileNotFoundError: [Errno 2] No such file or directory error is often raised by the os library. This error tells you that you are trying to access a file or folder that does not exist. To fix this error, check that you are referring to the right file or folder in your program.

Where are python scripts stored?

Common places for Python to be installed on is in C:\PythonXY or %AppData%\Roaming\Python\PythonXY . To run Python scripts, you need to pass a filename as an argument to python.exe so python.exe can run it.

How do you prompt an error in python?

Using try , except and raise Since ValueError inherits from the Exception class, the first parameter when creating a ValueError object is the message it prints: try: int("string") #the code that raises the error except ValueError: raise ValueError("Your custom message here.")

How do I execute a python script?

To run Python scripts with the python command, you need to open a command-line and type in the word python , or python3 if you have both versions, followed by the path to your script, just like this: $ python3 hello.py Hello World! If everything works okay, after you press Enter , you'll see the phrase Hello World!


2 Answers

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 {} \;
like image 179
fpbhb Avatar answered Sep 24 '22 02:09

fpbhb


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.

like image 33
Grismar Avatar answered Sep 26 '22 02:09

Grismar