转换为Jython的Python 3.5项目-UnicodeDecodeError:'unicodeescape'编解码器无法解码位置4-10的字节:非法Unicode字符 [英] Converting to Jython a Python 3.5 project - UnicodeDecodeError: 'unicodeescape' codec can't decode bytes in position 4-10: illegal Unicode character

查看:176
本文介绍了转换为Jython的Python 3.5项目-UnicodeDecodeError:'unicodeescape'编解码器无法解码位置4-10的字节:非法Unicode字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的最终目的是将正在运行的Python项目转换为Jython解释器,因为将要添加一些Java API.

My final purpose is to convert a running Python project to Jython interpreter because some java API's are going to be added.

详细信息:

  • 最新的Jython是2.7
  • 我拥有的项目可以在Python 3.5中运行

所以我采取了以下方法:

第一件事是使用future模块将我的项目转换为Python 2.7,并对可执行文件进行巴氏灭菌. 此步骤已成功完成.

First thing was to convert my project to Python 2.7 utilizing the future module and pasteurize executable. This step was done successfully.

第二件事是将Python 2.7项目转换为Jython 2.7项目. 在Eclipse mars上切换解释器时,指示以下错误:

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.

要解决此问题,通过传递编码参数-Dpython.console.encoding=UTF-8来使用此帖子的解决方案根据下图连接到Java VM:

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

通过命令行运行Jython会缩短错误日志:

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?

Jython.org创建了一个 bug ,它的严重性很高,因为许多人已经在使用最新的Python模块和解释器.他们可能想将Java功能添加到他们的代码中.因此,他们基本上必须采取与我相同的道路.将该项目先移植到Python 2.7,然后再移植到Jython 2.7.

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.

在python-future上,也记录了功能请求错误./p>

At python-future a feature request bug was recorded too.

推荐答案

如Roland Smith所建议的那样,依赖py4j是将应用程序移植到JVM环境的好方法.

Relying on py4j, as Roland Smith suggests, would be a good approach for porting your app to a JVM environment.

这篇关于转换为Jython的Python 3.5项目-UnicodeDecodeError:'unicodeescape'编解码器无法解码位置4-10的字节:非法Unicode字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆