Scalene:UnicodeEncodeError 类型的异常

问题描述 投票:0回答:2

我尝试使用 %%scalene 在 Jupyter 中的 .ipynb fily 中运行 Scalene 并收到以下错误:

Scalene: An exception of type UnicodeEncodeError occurred. Arguments:
('charmap', '\r\n<html>\r\n  <head>\r\n    <title>Scalene</title> ...

接下来是基本上整个 Scalene Github 网站 html 代码,并以:

结尾
Traceback (most recent call last):
  File "C:\Users\marci\anaconda3\envs\wc2022v2_env\lib\site-packages\scalene\scalene_profiler.py", line 1949, in run_profiler
    exit_status = profiler.profile_code(
  File "C:\Users\marci\anaconda3\envs\wc2022v2_env\lib\site-packages\scalene\scalene_profiler.py", line 1781, in profile_code
    Scalene.generate_html(profile_fname=Scalene.__profile_filename, output_fname=Scalene.__profiler_html)
  File "C:\Users\marci\anaconda3\envs\wc2022v2_env\lib\site-packages\scalene\scalene_profiler.py", line 1729, in generate_html
    f.write(rendered_content)
  File "C:\Users\marci\anaconda3\envs\wc2022v2_env\lib\encodings\cp1250.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\xa3' in position 79534: character maps to <undefined>

我是否认为是网站编码导致了此错误?还是浏览器的问题?

如果还有什么:可以采取什么措施?

python 3.8.15

python jupyter-notebook profiler scalene
2个回答
1
投票

遇到与 cp1250 相关的相同错误。似乎 scalene 分析器没有费心去测试国家环境。尝试使用

chcp 65001
将运行时设置为 utf-8,但没有帮助。

我的修复方法是在第 1728 行破解其源代码“

(...)\scalene\scalene_profiler.py
”: 而不是:

with open(output_fname, "w") as f:

用途:

with open(output_fname, "w", encoding='utf-8') as f:

问题就解决了。


1
投票

此问题已修复,如 https://stackoverflow.com/a/74696070/335756 所示。请安装当前版本(1.5.20或更高版本);那应该可以解决你的问题。 (此外,如果有任何未来问题,请在 https://github.com/plasma-umass/scalene 上发布!)

© www.soinside.com 2019 - 2024. All rights reserved.