Python 3 fails at pdb "b main" with UnicodeDecodeError? - python

The only similar question to this I've found is Django UnicodeDecodeError when using pdb - unfortunately, the solution there does not apply to this case.
Consider the following code, test.py:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# encoding: utf-8
def subtract(ina, inb):
myresult = ina - inb
return myresult
def main():
y2 = 10
y1 = 7
# calculate (y₂-y₁)
print("Calculating difference between y2: {} and y1: {}".format(y2, y1))
result = subtract(y2, y1)
print("The result is: {}".format(result))
if __name__ == '__main__':
main()
Using Python3 from Anaconda3 on Windows 10:
(base) C:\tmp>conda --version
conda 4.7.12
(base) C:\tmp>python --version
Python 3.7.3
... I can run this program without a problem:
(base) C:\tmp>python test.py
Calculating difference between y2: 10 and y1: 7
The result is: 3
However, if I want to debug/step through this program using pdb, it fails as soon as I type b main to set a breakpoint on the main function:
(base) C:\tmp>python -m pdb test.py
> c:\tmp\test.py(6)<module>()
-> def subtract(ina, inb):
(Pdb) b main
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\pdb.py", line 648, in do_break
lineno = int(arg)
ValueError: invalid literal for int() with base 10: 'main'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\pdb.py", line 659, in do_break
code = func.__code__
AttributeError: 'str' object has no attribute '__code__'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\pdb.py", line 1701, in main
pdb._runscript(mainpyfile)
File "C:\ProgramData\Anaconda3\lib\pdb.py", line 1570, in _runscript
self.run(statement)
File "C:\ProgramData\Anaconda3\lib\bdb.py", line 585, in run
exec(cmd, globals, locals)
File "<string>", line 1, in <module>
File "c:\tmp\test.py", line 6, in <module>
def subtract(ina, inb):
File "c:\tmp\test.py", line 6, in <module>
def subtract(ina, inb):
File "C:\ProgramData\Anaconda3\lib\bdb.py", line 88, in trace_dispatch
return self.dispatch_line(frame)
File "C:\ProgramData\Anaconda3\lib\bdb.py", line 112, in dispatch_line
self.user_line(frame)
File "C:\ProgramData\Anaconda3\lib\pdb.py", line 261, in user_line
self.interaction(frame, None)
File "C:\ProgramData\Anaconda3\lib\pdb.py", line 352, in interaction
self._cmdloop()
File "C:\ProgramData\Anaconda3\lib\pdb.py", line 321, in _cmdloop
self.cmdloop()
File "C:\ProgramData\Anaconda3\lib\cmd.py", line 138, in cmdloop
stop = self.onecmd(line)
File "C:\ProgramData\Anaconda3\lib\pdb.py", line 418, in onecmd
return cmd.Cmd.onecmd(self, line)
File "C:\ProgramData\Anaconda3\lib\cmd.py", line 217, in onecmd
return func(arg)
File "C:\ProgramData\Anaconda3\lib\pdb.py", line 667, in do_break
(ok, filename, ln) = self.lineinfo(arg)
File "C:\ProgramData\Anaconda3\lib\pdb.py", line 740, in lineinfo
answer = find_function(item, fname)
File "C:\ProgramData\Anaconda3\lib\pdb.py", line 100, in find_function
for lineno, line in enumerate(fp, start=1):
File "C:\ProgramData\Anaconda3\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 199: character maps to <undefined>
Uncaught exception. Entering post mortem debugging
Running 'cont' or 'step' will restart the program
> c:\programdata\anaconda3\lib\encodings\cp1252.py(23)decode()
-> return codecs.charmap_decode(input,self.errors,decoding_table)[0]
(Pdb) q
Post mortem debugger finished. The test.py will be restarted
> c:\tmp\test.py(6)<module>()
-> def subtract(ina, inb):
(Pdb) q
(base) C:\tmp>
The problem is the comment line: # calculate (y₂-y₁); if it is deleted, then pdb starts fine:
(base) C:\tmp>python -m pdb test.py
> c:\tmp\test.py(6)<module>()
-> def subtract(ina, inb):
(Pdb) b main
Breakpoint 1 at c:\tmp\test.py:10
(Pdb) q
(base) C:\tmp>
I'm slightly surprised by this - wasn't Python3 supposed to be "utf-8 by default"?
Obviously, this is a trivial case where I can easily erase the single comment line that causes the trouble. However, I have a large script, where I have utf-8 characters all over the place, both in comments, and in prints I'd actually want to step through, and it is not really viable to go in and manually change all those instances to UTF-8 characters.
So, is there a way to cheat Python3's pdb, so it works - even if there are utf-8 characters present in the source code (regardless if in comments, or in actual commands)?

Python 3 is UTF-8 by default, but the environment in which it is operating is not - it has a default encoding of cp1252.
You can set the PYTHONIOENCODING environment variable to UTF-8 to override the default encoding, or change the environment to use UTF-8.
Edit
I analysed this too hastily. The above solutions apply to fixing unicode errors raised when reading or writing from stdin/stdout, but the problem here is that pdb opens a file for reading without specifying an encoding:
def find_function(funcname, filename):
cre = re.compile(r'def\s+%s\s*[(]' % re.escape(funcname))
try:
fp = open(filename)
except OSError:
return None
If no encoding is specified, according to the io docs Python will default to using the result of locale.getpreferredencoding - presumably cp1252 in this case.
One solution might be to set the console locale before running the debugger.
It may also be possible to set the PYTHONUTF8 environment variable to 1. Amongst other things, this will cause
open(), io.open(), and codecs.open() use the UTF-8 encoding by default.

Related

bin/sh: 1: visqol: not found

When I execute my code it shows me error as below, I don't know what is this visqol_find.py:33 ERROR: /bin/sh: 1: visqol: not found meaning, and I pretty sure that visqol_value and visqol_threshold are both defined as float because the program is working fine with my professor.
My system is Ubuntu 18.04 and python is 3.6.12.
This is code for visqol_value
def visqol(reference_file: str, degraded_file: str, visqol_model_path: str = __visqol_model_path__) -> float:
status, output = subprocess.getstatusoutput("visqol --reference_file {} --degraded_file {} --similarity_to_quality_model {} --use_speech_mode".format(reference_file, degraded_file, visqol_model_path))
if status != 0:
for _line_ in output.split('\n'):
logger.error(_line_)
raise RuntimeError("VISQOL Command-Line Error.")
visqol_score = None
for output_line in output.split("\n"):
if output_line.startswith('MOS-LQO:'):
visqol_score = float(output_line.split()[1])
if visqol_score is not None:
return visqol_score
raise RuntimeError("VISQOL Command-Line Error.")
visqol_value = visqol(clip_file, adversarial_path)
if visqol_value < visqol_threshold:
right_bound = potential_delta
if _delete_failed_wav_: # delete
for _file_ in glob.glob(adversarial_path[:-4] + "*"):
os.remove(_file_)
logger.debug("VISQOL Exceeds for music clip '{}' with 'delta_db={}'.".format(clip_name, potential_delta))
continue
This is code for visqol_threshold
def get_visqol_threshold(formant_weight: Union[list, np.ndarray], phoneme_num: int) -> float:
formant_weight = np.array(formant_weight)
_alpha = 0.95 # The higher the value of _alpha and _beta is, the faster the visqol threshold decreases.
_beta = 8.0
_theta = 10.0
o = np.sum(formant_weight != 0.)
if o == 5:
base = 1.7
elif o == 4:
base = 1.8
elif o == 3:
base = 2.2
else:
if formant_weight[1] < 0.75:
base = 2.3
else:
base = 2.25
return base * (_alpha ** (max((phoneme_num - _theta) / _beta, 0.)))
I would like to know how I should fix it?
Since I am running this project in a virtual python environment, is it possible that it is because I put visqol in the wrong place, and if so, where should I download visqol to
The program works but keeps looping with these two error messages until I manually terminate it
(.venv) dunliu#dun:~/research/Phantom-of-Formants-master$ python3 2022gen_100song_bing_001.py
2022-11-13 17:23:58 2022gen_100song_bing_001.py:433 WARNING: The destination folder './task/weather1/generate/0490c9606d8e333e' will be removed. Please backup this folder, and then enter 'Y' to continue, or others to exit...
y
2022-11-13 17:24:01 2022gen_100song_bing_001.py:437 INFO: The destination folder './task/weather1/generate/0490c9606d8e333e' was removed.
2022-11-13 17:24:01 2022gen_100song_bing_001.py:325 INFO: ******************** Start Binary-search Generation. ********************
2022-11-13 17:24:01 visqol_find.py:34 ERROR: /bin/sh: 1: visqol: not found
2022-11-13 17:24:01 utils.py:361 ERROR: program exit!
Traceback (most recent call last):
File "/home/dunliu/research/Phantom-of-Formants-master/utils.py", line 357, in wrapper
return function(*args, **kwargs)
File "/home/dunliu/research/Phantom-of-Formants-master/visqol_find.py", line 35, in visqol
raise RuntimeError("VISQOL Command-Line Error.")
RuntimeError: VISQOL Command-Line Error.
2022-11-13 17:24:01 utils.py:361 ERROR: program exit!
Traceback (most recent call last):
File "/home/dunliu/research/Phantom-of-Formants-master/utils.py", line 357, in wrapper
return function(*args, **kwargs)
File "2022gen_100song_bing_001.py", line 257, in generate
if visqol_value < visqol_threshold:
TypeError: '<' not supported between instances of 'NoneType' and 'float'
2022-11-13 17:24:01 visqol_find.py:34 ERROR: /bin/sh: 1: visqol: not found
2022-11-13 17:24:01 utils.py:361 ERROR: program exit!
Traceback (most recent call last):
File "/home/dunliu/research/Phantom-of-Formants-master/utils.py", line 357, in wrapper
return function(*args, **kwargs)
File "/home/dunliu/research/Phantom-of-Formants-master/visqol_find.py", line 35, in visqol
raise RuntimeError("VISQOL Command-Line Error.")
RuntimeError: VISQOL Command-Line Error.
2022-11-13 17:24:01 utils.py:361 ERROR: program exit!
Traceback (most recent call last):
File "/home/dunliu/research/Phantom-of-Formants-master/utils.py", line 357, in wrapper
return function(*args, **kwargs)
File "2022gen_100song_bing_001.py", line 257, in generate
if visqol_value < visqol_threshold:
TypeError: '<' not supported between instances of 'NoneType' and 'float'
after I terminate it, it shows
^CTraceback (most recent call last):
File "2022gen_100song_bing_001.py", line 448, in <module>
binary_generation_task()
File "2022gen_100song_bing_001.py", line 444, in binary_generation_task
binary_generation(params)
File "2022gen_100song_bing_001.py", line 395, in binary_generation
generate(_wake_up_analysis_file_, _command_analysis_file_, _clip_file_, output_folder, params)
File "/home/dunliu/research/Phantom-of-Formants-master/utils.py", line 359, in wrapper
raise _err
File "/home/dunliu/research/Phantom-of-Formants-master/utils.py", line 357, in wrapper
return function(*args, **kwargs)
File "2022gen_100song_bing_001.py", line 251, in generate
adversarial_path = gen_by_command(delta_db_list, bandwidth_list, command_analysis_file, clip_file, output_folder, adversarial_filename, params)
File "/home/dunliu/research/Phantom-of-Formants-master/utils.py", line 359, in wrapper
raise _err
File "/home/dunliu/research/Phantom-of-Formants-master/utils.py", line 357, in wrapper
return function(*args, **kwargs)
File "/home/dunliu/research/Phantom-of-Formants-master/formant_processor.py", line 688, in gen_by_command
command_filter_list = generate_filter(command_formant_list, m_sample_rate, bandwidth, min_fre, max_fre, filter_order, reserved_fre_gap_ratio)
File "/home/dunliu/research/Phantom-of-Formants-master/formant_processor.py", line 356, in generate_filter
signal.butter(f_order, [_s_fre_, _e_fre_], btype='band', output='sos')
File "/home/dunliu/research/Phantom-of-Formants-master/.venv/lib/python3.6/site-packages/scipy/signal/filter_design.py", line 2894, in butter
output=output, ftype='butter', fs=fs)
File "/home/dunliu/research/Phantom-of-Formants-master/.venv/lib/python3.6/site-packages/scipy/signal/filter_design.py", line 2407, in iirfilter
return zpk2sos(z, p, k)
File "/home/dunliu/research/Phantom-of-Formants-master/.venv/lib/python3.6/site-packages/scipy/signal/filter_design.py", line 1447, in zpk2sos
z = np.concatenate(_cplxreal(z))
File "/home/dunliu/research/Phantom-of-Formants-master/.venv/lib/python3.6/site-packages/scipy/signal/filter_design.py", line 887, in _cplxreal
z = atleast_1d(z)
File "<__array_function__ internals>", line 6, in atleast_1d
File "/home/dunliu/research/Phantom-of-Formants-master/.venv/lib/python3.6/site-packages/numpy/core/shape_base.py", line 25, in atleast_1d
#array_function_dispatch(_atleast_1d_dispatcher)
KeyboardInterrupt
The error message is from /bin/sh. That means you are expecting your (bash/dash/other) shell to execute a Python script which isn't going to work.
You need to either put a Python shebang as the first line of your script, e.g.
#!/usr/bin/env python3
...
... rest of script
then make it executable with:
chmod +x YOURSCRIPT.PY
and run with:
./YOURSCRIPT.PY
Or, you need to start it like this, specifically with the Python interpreter:
python3 YOURSCRIPT.PY
Because you didn't specify the visqol's absolute path in the shell script, your code couldn't call the visqol.
I suggest specifying the visqol's absolute path.
try the command below in your shell ( Or your terminal ).
which visqol
If the path exist, then replace "visqol" in the code below with the result above.
status, output = subprocess.getstatusoutput("visqol --reference_file {} --degraded_file {} --similarity_to_quality_model {} --use_speech_mode".format(reference_file, degraded_file, visqol_model_path))
It looks like "~~ getstatusoutput("/absolute/path/visqol --reference_file ~~"
If not, install "visqol" via the code below in your shell (OR terminal) and try the solution above.
# install bazel to build visqol
# https://bazel.build/install/ubuntu
sudo apt install apt-transport-https curl gnupg
sudo apt update && sudo apt install bazel
sudo apt update && sudo apt full-upgrade
# install numpy python library.
# https://github.com/google/visqol#linuxmac-build-instructions
pip install numpy
# download source code and build visqol
# https://github.com/google/visqol#linuxmac-build-instructions
git clone https://github.com/google/visqol.git
cd visqol
bazel build :visqol -c opt

How to fix 'UnicodeDecodeError' in 'envreport' when running tox?

I want to use tox to automate testing of my python package. As of now, just locally. When running tox, the test passes, but then a UnicodeDecodeError is thrown. tox --version is 3.13.2.
The error message (full traceback below):
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe4 in position 70: invalid continuation byte
The tests succeed when running tox, which is visualize with -vvvvvv, which I expect. The functions do not do anything and are just a dummy at the moment (Automatically created using the cookiecutter-pypackage). I reduced the items in the envlist to just py37. Anaconda is in my PATH variable and no regular python is installed. I tried using different python versions by writing a .bat (i am using Windows) like on the official tox documentation. This works identically to the py37. Test pass and the following is thrown.
I could not find anything in the tox documentation regarding UnicodeDecodeErrors.
Neither powershell or my commandline can execute export LANG=en_US.UTF-8 as suggested in this post. Setting setenv = LANG=en_US.UTF-8 in the tox.ini also did not change anything.
The Traceback below is for the py37 environment, which gets called when adding skipdist = true to tox.ini. Leaving that out will still return the exact same error, with an almost identical traceback.
The error is thrown from codecy.py file. Moving up in the Traceback and looking into each file didn't help me, as i could not find out, which file gets encoded or anything else, which could help. Without posting the whole console output with the successful virtualenv creation, something could help. The Error is thrown on the envreport in the summary. tox-envreport is not installed if that matters. When the sdist gets tested, it is in the GLOB sdist-make: section.
py37 finish: finishvenv after 0.02 seconds
py37 start: envreport
setting PATH=C:\Users\cosmo\OneDrive - Universität zu Köln\package\.tox\py37\Scripts;C:\Users\cosmo\Anaconda3;C:\Users\cosmo\Anaconda3\Library\mingw-w64\bin;C:\Users\cosmo\Anaconda3\Library\usr\bin;C:\Users\cosmo\Anaconda3\Library\bin;C:\Users\cosmo\Anaconda3\Scripts;C:\Users\cosmo\Anaconda3\bin;C:\Users\cosmo\Anaconda3\condabin;C:\ProgramData\DockerDesktop\version-bin;C:\Program Files\Docker\Docker\Resources\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Program Files\Git\cmd;C:\Program Files\MATLAB\R2019a\bin;C:\Program Files\PuTTY;C:\Program Files\MiKTeX 2.9\miktex\bin\x64;C:\Users\cosmo\AppData\Local\Microsoft\WindowsApps;C:\Users\cosmo\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\cosmo\AppData\Local\GitHubDesktop\bin;C:\Users\cosmo\Anaconda3\Scripts;C:\Users\cosmo\Anaconda3;.
[7836] C:\Users\cosmo\OneDrive - Universität zu Köln\package$ 'C:\Users\cosmo\OneDrive - Universität zu Köln\package\.tox\py37\Scripts\python.EXE' -m pip freeze >.tox\py37\log\py37-0.log
_________________________________________________________________________ summary __________________________________________________________________________
py37: commands succeeded
congratulations :)
Traceback (most recent call last):
File "c:\users\cosmo\anaconda3\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\users\cosmo\anaconda3\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\cosmo\Anaconda3\Scripts\tox.exe\__main__.py", line 9, in <module>
File "c:\users\cosmo\anaconda3\lib\site-packages\tox\session\__init__.py", line 44, in cmdline
main(args)
File "c:\users\cosmo\anaconda3\lib\site-packages\tox\session\__init__.py", line 68, in main
exit_code = session.runcommand()
File "c:\users\cosmo\anaconda3\lib\site-packages\tox\session\__init__.py", line 192, in runcommand
return self.subcommand_test()
File "c:\users\cosmo\anaconda3\lib\site-packages\tox\session\__init__.py", line 220, in subcommand_test
run_sequential(self.config, self.venv_dict)
File "c:\users\cosmo\anaconda3\lib\site-packages\tox\session\commands\run\sequential.py", line 20, in run_sequential
runenvreport(venv, config)
File "c:\users\cosmo\anaconda3\lib\site-packages\tox\session\commands\run\sequential.py", line 60, in runenvreport
packages = config.pluginmanager.hook.tox_runenvreport(venv=venv, action=action)
File "c:\users\cosmo\anaconda3\lib\site-packages\pluggy\hooks.py", line 289, in __call__
return self._hookexec(self, self.get_hookimpls(), kwargs)
File "c:\users\cosmo\anaconda3\lib\site-packages\pluggy\manager.py", line 87, in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
File "c:\users\cosmo\anaconda3\lib\site-packages\pluggy\manager.py", line 81, in <lambda>
firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
File "c:\users\cosmo\anaconda3\lib\site-packages\pluggy\callers.py", line 208, in _multicall
return outcome.get_result()
File "c:\users\cosmo\anaconda3\lib\site-packages\pluggy\callers.py", line 80, in get_result
raise ex[1].with_traceback(ex[2])
File "c:\users\cosmo\anaconda3\lib\site-packages\pluggy\callers.py", line 187, in _multicall
res = hook_impl.function(*args)
File "c:\users\cosmo\anaconda3\lib\site-packages\tox\venv.py", line 780, in tox_runenvreport
output = venv._pcall(args, cwd=venv.envconfig.config.toxinidir, action=action, returnout=True)
File "c:\users\cosmo\anaconda3\lib\site-packages\tox\venv.py", line 574, in _pcall
report_fail=not is_test_command,
File "c:\users\cosmo\anaconda3\lib\site-packages\tox\action.py", line 107, in popen
lines = out_path.read_text("UTF-8").split("\n")
File "c:\users\cosmo\anaconda3\lib\site-packages\py\_path\common.py", line 165, in read_text
return f.read()
File "c:\users\cosmo\anaconda3\lib\codecs.py", line 322, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe4 in position 70: invalid continuation byte
My question:
How can i fix this?
What file may be the reason for this (seemingly bad enconding)?
Just a guess.
Place your application outside this folder: OneDrive - Universität zu Köln
The problem in Köln I think.
This is good traceback to feel tox bug report.

rabbitmqadmin can't handle unicode?

I might have stumbled into something that appears to be a bug with how rabbitmqadmin handles (or in fact, doesn't handle) unicode.
If I have a queue that has unicode characters in queue name the rabbitmqadmin command fails with UnicodeEncodeErrors.
I'm running RabbitMQ 3.6.6 on Mac, installed via Homebrew. Both the admin command and server are of same version.
Steps how to reproduce the queue name issue:
Create a queue with unicode in it: 'rabbitmqadmin declare queue name=ööö'.
List queues: 'rabbitmqadmin list queues'
Output:
Traceback (most recent call last):
File "/usr/local/sbin/rabbitmqadmin", line 1007, in <module>
main()
File "/usr/local/sbin/rabbitmqadmin", line 413, in main
method()
File "/usr/local/sbin/rabbitmqadmin", line 588, in invoke_list
format_list(self.get(uri), cols, obj_info, self.options)
File "/usr/local/sbin/rabbitmqadmin", line 705, in format_list
formatter_instance.display(json_list)
File "/usr/local/sbin/rabbitmqadmin", line 716, in display
(columns, table) = self.list_to_table(json.loads(json_list), depth)
File "/usr/local/sbin/rabbitmqadmin", line 770, in list_to_table
add('', 1, item, add_to_row)
File "/usr/local/sbin/rabbitmqadmin", line 749, in add
fun(column, subitem)
File "/usr/local/sbin/rabbitmqadmin", line 756, in add_to_row
row[column_ix[col]] = str(val)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 12-13: ordinal not in range(128)
I have similar issues with 'rabbitmqadmin get queue=' when the message payload contains unicode character(s).
I think you are right, you can use python3 , check this answer it explains why with python3 works.
EDIT
1 - I filed an issue
2 - Fixed to the version: 3.6.7 see the PR

Converting to Jython a Python 3.5 project - UnicodeDecodeError: 'unicodeescape' codec can't decode bytes in position 4-10: illegal Unicode character

My final purpose is to convert a running Python project to Jython interpreter because some java API's are going to be added.
Details:
The latest Jython is 2.7
The project I have is runnable with Python 3.5
So I took the following approach:
First thing was to convert my project to Python 2.7 utilizing the future module and pasteurize executable.
This step was done successfully.
Second thing is to convert the Python 2.7 project to a Jython 2.7 Project.
Switching the interpreter at Eclipse mars, the following error was indicated:
console: Failed to install '': java.nio.charset.UnsupportedCharsetException: cp0.
To workaround it, the solution from this post was utilized by passing the encoding argument -Dpython.console.encoding=UTF-8 to the java VM according to figure below:
Thumbs were up when trying to run again. But unfortunately here, the error shown below just appeared. As I don't plan to change any imported module if there's no need to do so, I decided to ask help here.
pydev debugger: starting (pid: 4216)
Traceback (most recent call last):
File "C:\Users\souzadan\.p2\pool\plugins\org.python.pydev_4.4.0.201510052309\pysrc\pydevd.py", line 2364, in <module>
globals = debugger.run(setup['file'], None, None, is_module)
File "C:\Users\souzadan\.p2\pool\plugins\org.python.pydev_4.4.0.201510052309\pysrc\pydevd.py", line 1784, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "C:\Users\souzadan\FirmwareDevTools\Workspaces\Eclipse\aPythonWorkspace\aPythonProject\aPythonFolder\aPythonFile.py", line 7, in <module>
standard_library.install_aliases()
File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\site-packages\future-0.15.2-py2.7.egg\future\standard_library\__init__.py", line 465, in install_aliases
from future.backports.urllib import request
File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\site-packages\future-0.15.2-py2.7.egg\future\backports\urllib\request.py", line 96, in <module>
from future.backports import email
File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\site-packages\future-0.15.2-py2.7.egg\future\backports\email\__init__.py", line 16, in <module>
from future.utils import surrogateescape
File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\site-packages\future-0.15.2-py2.7.egg\future\utils\surrogateescape.py", line 167, in <module>
FS_ENCODING = 'ascii'; fn = b('[abc\xff]'); encoded = u('[abc\udcff]')
File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\site-packages\future-0.15.2-py2.7.egg\future\utils\surrogateescape.py", line 25, in u
return text.decode('unicode_escape')
UnicodeDecodeError: 'unicodeescape' codec can't decode bytes in position 4-10: illegal Unicode character
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\atexit.py", line 24, in _run_exitfuncs
func(*targs, **kargs)
File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\threading.py", line 297, in _MainThread__exitfunc
t.join()
File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\threading.py", line 128, in join
raise RuntimeError("cannot join current thread")
RuntimeError: cannot join current thread
Error in sys.exitfunc:
Traceback (most recent call last):
File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\atexit.py", line 24, in _run_exitfuncs
func(*targs, **kargs)
File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\threading.py", line 297, in _MainThread__exitfunc
t.join()
File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\threading.py", line 128, in join
raise RuntimeError("cannot join current thread")
RuntimeError: cannot join current thread
Running Jython through the command line results in a shorter error log:
Traceback (most recent call last):
File "somePythonCode.py", line 7, in <module>
standard_library.install_aliases()
File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\site-packages\future-0.15.2-py2.7.egg\future\standard_library\__init__.py", line 465, in install_aliases
from future.backports.urllib import request
File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\site-packages\future-0.15.2-py2.7.egg\future\backports\urllib\request.py", line 96, in <module>
from future.backports import email
File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\site-packages\future-0.15.2-py2.7.egg\future\backports\email\__init__.py", line 16, in <module>
from future.utils import surrogateescape
File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\site-packages\future-0.15.2-py2.7.egg\future\utils\surrogateescape.py", line 167, in <module>
FS_ENCODING = 'ascii'; fn = b('[abc\xff]'); encoded = u('[abc\udcff]')
File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\site-packages\future-0.15.2-py2.7.egg\future\utils\surrogateescape.py", line 25, in u
return text.decode('unicode_escape')
UnicodeDecodeError: 'unicodeescape' codec can't decode bytes in position 4-10: illegal Unicode character
Does anybody have a clue of how to solve this error in the most elegant manner?
A bug was created at Jython.org with a critical severity because many people are utilizing already the latest Python modules and interpreter. And they might want to add Java functionality to their code. So they would basically have to take same path as I did. Backporting the project to Python 2.7 then to Jython 2.7 subsequentely.
At python-future a feature request bug was recorded too.
Relying on py4j, as Roland Smith suggests, would be a good approach for porting your app to a JVM environment.

Spyder - Python - UnicodeDecodeError: 'ascii' codec can't decode

TL, DR: A python file encounters the UnicodeDecodeError when ran in Spyder, but works when I ran it in command line.
I downloaded a Python module that wraps a C implementation of a suffix tree. After built, it was ran in Spyder but I got the following error:
runfile('F:/src/suffix_tree-2.1/build/lib.win32-2.7/suffix_tree.py',
wdir='F:/src/suffix_tree-2.1/build/lib.win32-2.7')
Traceback (most recent call last):
File
"G:\IDE\python\Anaconda\lib\site-packages\IPython\core\interactiveshell.py",
line 3052, in run_code
self.showtraceback()
File
"G:\IDE\python\Anaconda\lib\site-packages\IPython\core\interactiveshell.py",
line 1851, in showtraceback
value, tb, tb_offset=tb_offset)
File
"G:\IDE\python\Anaconda\lib\site-packages\IPython\core\ultratb.py",
line 1240, in structured_traceback
self, etype, value, tb, tb_offset, number_of_lines_of_context)
File
"G:\IDE\python\Anaconda\lib\site-packages\IPython\core\ultratb.py",
line 1157, in structured_traceback
self, etype, value, elist, tb_offset, number_of_lines_of_context
File
"G:\IDE\python\Anaconda\lib\site-packages\IPython\core\ultratb.py",
line 511, in structured_traceback
lines = ''.join(self._format_exception_only(etype, value))
File
"G:\IDE\python\Anaconda\lib\site-packages\IPython\core\ultratb.py",
line 623, in _format_exception_only
Colors.Normal, s))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xb2 in position
20: ordinal not in range(128)
This error appears right after I import _suffix_tree.pyd, even before any other operations.
However, if I run the file in command line (cmd), it works successfully without any error.
PS: I use Windows, and my user name are ASCII characters.
You are possibly trying to open a file encoded in a different format of your system, you should check it and set Spyder using the commands below.
import sys
reload(sys)
sys.setdefaultencoding('utf8')
If this does not work, check the version of the Python kernel of the program. You can get this message trying to run an Python 3 code in an Spyder 2.

Categories

Resources