Code works in "run" but not "debug"

Answered

I keep running into this problem when trying to debug (I'm an experienced c++, etc. programmer, relatively new to to python), and then I don't. I could probably reduce this to a more trivial case, but it's just what popped up. 

Code:  <test3.py>
-----------------------
labels = ["author",
        "treatise",
        "book",
        "chapter",
        "section",
        "body"]

first = ["Augustine",
         "De Agone Christiano",
         "1",
         "1",
         "AC_001_001_001",
         "Corona victoriae "]

labels.append(first)
print(labels)
------------------

Runs just fine when I “run ‘test3.py’” (^shiftR) but when I debug ("debug ‘test3.py’"  (^shiftD)) I get 

-----------------
Traceback (most recent call last):
 File "/Applications/PyCharm.app/Contents/plugins/python-ce/helpers/pydev/pydevd.py", line 1570, in _exec
   pydev_imports.execfile(file, globals, locals)  # execute the script
   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 File "/Applications/PyCharm.app/Contents/plugins/python-ce/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 11, in execfile
   stream = tokenize.open(file)  # @UndefinedVariable
            ^^^^^^^^^^^^^
AttributeError: module 'tokenize' has no attribute 'open'
-------------------
 

I have Huggingface datasets, tokenizers, and transformers installed, but not imported. I can debug this in the shell running the python debugger in what I think is the same venv.

What am I missing? It's like I've got some piece of code invisibly (to me) loaded.

Thanks,

Walt Knowles
 

 

0
2 comments

Do you have a tokenize.py on your project? Try to rename it and debug again - Check out the following: https://github.com/pytorch/text/issues/348#issuecomment-771609408

0

I don't, but thanks for the help; it pointed me in a useful direction. It looks like the offending code in PyCharm (_pydev_execfile.py) was trying to fix a problem that I may not have:

------

#It seems that the best way is using tokenize.open(): http://code.activestate.com/lists/python-dev/131251/
import tokenize
stream = tokenize.open(file)  # @UndefinedVariable
  try:
      contents = stream.read()
  finally:
      stream.close()

-----

I commented out the import and made the 3rd line use the base library:
stream = open(file) 

We'll see what blows up next. 

The other possibility is that I have Spyder 6 installed as well as PyCharm. I found that PyCharm seems to work better for me, so I may just blow Spyder away and see if that fixes the problem.

Walt Knowles

0

Please sign in to leave a comment.