gruns / icecream

🍦 Never use print() to debug again.
MIT License
9.07k stars 184 forks source link

ic| Error: Failed to access the underlying source code for analysis. #169

Closed mhechthz closed 3 days ago

mhechthz commented 11 months ago

This was already in the issues but nevertheless I face this currently.

from icecream import ic

a = 3
b = 4
ic(a+b)

ic| Error: Failed to access the underlying source code for analysis. Was ic() invoked in a REPL (e.g. from the command line), a frozen application (e.g. packaged with PyInstaller), or did the underlying source code change during execution?

Windows 10, Python 3.11.6. On the same machine Python 3.10 and Python 3.12 work fine, but 3.11 not.

python -VV
Python 3.11.6 (tags/v3.11.6:8b6ee5b, Oct  2 2023, 14:57:12) [MSC v.1935 64 bit (AMD64)]
char101 commented 11 months ago

Works for me with python 3.11.6 on Windows. You could test if executing works first e.g.

import inspect

import executing

def test(expr):
    source = executing.Source.executing(inspect.currentframe().f_back)
    print(source.text()) # should print `test(a + b)`

a = 3
b = 4
test(a + b)

If it doesn't work then the problem is in executing, then you could debug the Source class in executing.

mhechthz commented 11 months ago

I think it might be an incompatibility with some library or so.

In Python 3.10 and 3.12 the print is as expected, in my 3.11.6 the print is empty.

TheStrangerDoctor commented 11 months ago

Please close this issue if it is solved to prevent comment cluttering. TQ

RainerFaller commented 10 months ago

I had the same problem with a fresh venv and Python 3.11.7. I resolved it by replacing the complete /site-packages/executing folder by the most recent source distribution 2.0.1

salabim commented 3 days ago

See an implementation on www.salabim.org/peek/

gruns commented 3 days ago

@salabim did you mean to post https://github.com/gruns/icecream/issues/169#issuecomment-2461452780 in https://github.com/gruns/icecream/issues/186?

RainerFaller commented 2 days ago

AnsgarNo, I did resolve my issue already some time ago as I mentioned in #169. Thank you for the great work. RainerAm 07.11.2024 um 16:00 schrieb Ansgar Grunseid @.***>: @salabim did you mean to post #169 (comment) in #186?

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: @.***>

salabim commented 2 days ago

@salabim did you mean to post #169 (comment) in #186?

Yes.