Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileNotFoundError: [Errno 2] No such file or directory: '<ipython-input-11-128260e0dc37>' #14

Closed
DanielGoldfarb opened this issue Mar 1, 2021 · 7 comments

Comments

@DanielGoldfarb
Copy link

---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-11-128260e0dc37> in <module>
----> 1 watch(plt.rcParams['axes.titleweight'])

~/.local/lib/python3.8/site-packages/watchpoints/watch.py in __call__(self, *args, **kwargs)
     26         with self.set_lock:
     27             frame = inspect.currentframe().f_back
---> 28             argnodes = getargnodes(frame)
     29             for node, name in argnodes:
     30                 self.watch_list.append(

~/.local/lib/python3.8/site-packages/watchpoints/util.py in getargnodes(frame)
     41     get the list of arguments of the current line function
     42     """
---> 43     line = getline(frame)
     44     m = re.match(r".*?\((.*)\)", line)
     45     if not m:  # pragma: no cover

~/.local/lib/python3.8/site-packages/watchpoints/util.py in getline(frame)
     17     filename = frame.f_code.co_filename
     18 
---> 19     with open(filename, "r", encoding="utf-8") as f:
     20         lines = f.readlines()
     21         if sys.version_info.minor <= 7:

FileNotFoundError: [Errno 2] No such file or directory: '<ipython-input-11-128260e0dc37>'

Let me know if you need more information. Running in jupyter notebook. This is my first time trying to use watchpoints. Does it not work with ipython? Will rework my code to run in a script; in the meantime will leave this post here in case you can help. Thanks.

@gaogaotiantian
Copy link
Owner

I'm not familiar with ipython but it's very likely that watchpoints does not work with ipython. However, I believe the part that does not work with ipython well is the print, because it's trying to access the file where the changes is written but in ipython it seems like that's not a file.

You can still caught the trigger of the variable change, but you need your own callback function. Check https://github.com/gaogaotiantian/watchpoints#customize-callback for more information. If you still have questions, feel free to ask!

@DanielGoldfarb
Copy link
Author

@gaogaotiantian
thanks so much! will take a look later today.

@gaogaotiantian
Copy link
Owner

@DanielGoldfarb oh wait, I think I was wrong. watchpoints can't support any kind of REPL, including ipython, because it's not able to parse the variable name from the file. You have to write a script(a file) to use the feature.

@gaogaotiantian
Copy link
Owner

Hi @DanielGoldfarb, I just checked in the code for REPL support, including ipython. I think you can use it now.

@DanielGoldfarb
Copy link
Author

@gaogaotiantian
Thanks. In the middle of something else right now. Will try to check it out next week. Much appreciated.

@dvirtz
Copy link

dvirtz commented Apr 19, 2021

It could be nice if it would work with VSCode python debubger as well.
The error I see there is

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/conan/.local/lib/python3.6/site-packages/watchpoints/watch.py", line 28, in __call__
    argnodes = getargnodes(frame)
  File "/home/conan/.local/lib/python3.6/site-packages/watchpoints/util.py", line 57, in getargnodes
    line = getline(frame)
  File "/home/conan/.local/lib/python3.6/site-packages/watchpoints/util.py", line 33, in getline
    with open(filename, "r", encoding="utf-8") as f:
FileNotFoundError: [Errno 2] No such file or directory: '<string>'

@gaogaotiantian
Copy link
Owner

Unfortunately, watchpoints requires source code to work, there's some black magic to make the UI super intuitive. I'm not super familiar with VSCode Python debugger, but there are two things that I'm pretty sure:

  1. It compiles the source code as string, so I don't think watchpoints can access the source code
  2. It uses sys.settrace to achieve debugger functions, which conflicts with watchpoints because watchpoints uses it as well

Overall, I doubt if watchpoints can be used with VSCode debugger, even with efforts to adapt it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants