【问题标题】:Scalene: An exception of type UnicodeEncodeErrorScalene:UnicodeEncodeError 类型的异常
【发布时间】:2022-12-06 09:08:10
【问题描述】:

我正在尝试使用 %%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>

我认为是网站编码导致此错误是否正确?还是浏览器?

如果还有什么:可以做些什么呢?

蟒蛇 3.8.15

【问题讨论】:

    标签: python jupyter-notebook profiler


    【解决方案1】:

    得到与 cp1250 相关的相同错误。似乎 scalene profiler 没有费心去测试国家环境。尝试使用 chcp 65001 将运行时设置为 utf-8,但没有帮助。

    我的解决方法是在第 1728 行破解其来源“(...)scalenescalene_profiler.py”: 代替:

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

    利用:

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

    那解决了问题。

    【讨论】:

      猜你喜欢
      • 2012-02-06
      • 2011-04-20
      • 2013-08-13
      • 1970-01-01
      • 1970-01-01
      • 2021-01-17
      • 2019-09-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多