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

Importing a module with debugger causes "TypeError: decoding Unicode is not supported" #2245

Closed
breedlun opened this issue Mar 14, 2015 · 7 comments

Comments

@breedlun
Copy link

Description

  • What steps will reproduce the problem?
  • Create a module with nothing in it except "print 'It worked!'"
  • Double click the line number in the module with the print statement to create a breakpoint.
  • Create a script that does nothing besides import the module
  • Run the script with the debugger.
  • What is the expected output? What do you see instead?

Expected output: 'It worked!' should print to the console.

Observed output:
Traceback (most recent call last):
File "", line 1, in
File "/Users/breedlu/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 700, in debugfile
debugger.run("runfile(%r, args=%r, wdir=%r)" % (filename, args, wdir))
File "/Applications/Canopy.app/appdata/canopy-1.5.1.2730.macosx-x86_64/Canopy.app/Contents/lib/python2.7/bdb.py", line 400, in run
exec cmd in globals, locals
File "", line 1, in
File "/Users/breedlu/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 680, in runfile
execfile(filename, namespace)
File "/Users/breedlu/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 78, in execfile
builtins.execfile(filename, *where)
File "/Users/breedlu/Desktop/generic_script.py", line 8, in
import generic_module
File "/Users/(username)/Documents/Python_Routines/generic_module.py", line 6, in
"""
File "/Users/(username)/Documents/Python_Routines/generic_module.py", line 6, in
"""
File "/Applications/Canopy.app/appdata/canopy-1.5.1.2730.macosx-x86_64/Canopy.app/Contents/lib/python2.7/bdb.py", line 49, in trace_dispatch
return self.dispatch_line(frame)
File "/Applications/Canopy.app/appdata/canopy-1.5.1.2730.macosx-x86_64/Canopy.app/Contents/lib/python2.7/bdb.py", line 66, in dispatch_line
if self.stop_here(frame) or self.break_here(frame):
File "/Users/breedlu/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 515, in break_here
filename = unicode(filename, "utf-8")
TypeError: decoding Unicode is not supported

  • Please provide any additional information below

When I use the pdb debugger explicitly with "import pdb" and "pdb.set_trace()" the issue does not occur.

In case it matters, I am using the full 64-bit version of Enthought Canopy python. I built spyder from source using Canopy.

Version and main components

  • Spyder Version: 2.3.3
  • Python Version: 2.7.6
  • Qt Version : 4.8.5, PySide 1.2.2 on Darwin

Optional dependencies

pyflakes >=0.5.0: 0.8.1 (OK)
pep8 >=0.6 : 1.5.7 (OK)
IPython >=1.0 : 2.4.1 (OK)
zmq >=2.1.11 : 14.5.0 (OK)
pygments >=1.6 : 2.0.2 (OK)
pandas >=0.13.1 : 0.15.2 (OK)
sphinx >=0.6.6 : 1.2.3 (OK)
psutil >=0.3 : 2.2.0 (OK)
jedi >=0.8.1 : None (NOK)
rope >=0.9.2 : 0.9.4 (OK)
matplotlib >=1.0: 1.4.2 (OK)
sympy >=0.7.0 : 0.7.6 (OK)
pylint >=0.25 : 0.25.1 (OK)

@ccordoba12 ccordoba12 added this to the v2.3.4 milestone Mar 14, 2015
@ccordoba12
Copy link
Member

Sorry for the problem. I introduced this bug when trying to fix debugging of non-ascii files on Windows. I'll fix it in 2.3.4

@breedlun
Copy link
Author

Great. Thanks for the quick fix!

@breedlun
Copy link
Author

Unfortunately, I still am having trouble with this in v2.3.4. The debugger works properly when I import a module that is in the same directory as my script. However, I still get

fname = unicode(fname, "utf-8")
TypeError: decoding Unicode is not supported

when I import a module that is somewhere else on my PYTHONPATH.

@ccordoba12
Copy link
Member

I missed that other instance of fname = unicode.... The fix is simple and I don't think it requires us to do another release.

Please take a look at issue #2277 to see where the fix needs to be applied.

@breedlun
Copy link
Author

Good to hear it can get fixed easily and that I won't have to wait for another release!

I am confused by your suggestion to "see where the fix needs to be applied". As just a user of spyder, I don't know where the fix should be applied. Did you mean "whether" instead of "where"? I took a look at #2277, and it looks like @greenorca fixed his/her problem by clearing the breakpoints from imported modules, so I am not sure anything more needs to be done. In my case, I created a fresh script with one line of code importing a module on my PYTHONPATH. In the module I just had a single print statement, and then set a breakpoint on the print statement.

@ccordoba12
Copy link
Member

Sorry for not being clear enough @stretch97. I meant that you need to look at the commit referenced in #2277 and apply it yourself to sitecustomize.py. It's just a three line patch.

@breedlun
Copy link
Author

breedlun commented Apr 1, 2015

I just tried the commit referenced in #2277, and it did not work. I then changed the commit from

if sys.version[0] == '2':
    try:
        filename = unicode(filename, "utf-8")
    except TypeError:
        pass
lineno = frame.f_lineno

to

if sys.version[0] == '2':
    try:
        fname = unicode(fname, "utf-8")
    except TypeError:
        pass
lineno = frame.f_lineno

and it worked. @ccordoba12, you may want to update the commit. Regardless, thanks for the help!

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

No branches or pull requests

2 participants