python-3.x - spyder 中的 UnicodeEncodeError Python 与活动进度
问题描述
我在 W10 中使用来自 anaconda 的 Spyder 4.1.1 和 Python 3.7.6。我正在为我的一个项目使用模块 alive-progress。只需使用以下代码的基本行:
from alive_progress import alive_bar
import time
for x in 3000, 4000, 2000, 0:
with alive_bar(x) as bar:
for i in range(3000):
time.sleep(0.002)
bar(0)
我收到下一个错误:
Traceback (most recent call last):
File "\\My_path\alive_bar.py", line 10, in <module>
bar(0)
File "C:\Users\delprf2\Anaconda3\lib\contextlib.py", line 119, in __exit__
next(self.gen)
File "C:\Users\delprf2\Anaconda3\lib\site-packages\alive_progress\progress.py", line 275, in alive_bar
alive_repr()
File "C:\Users\delprf2\Anaconda3\lib\site-packages\alive_progress\progress.py", line 118, in alive_repr
sys.__stdout__.write(line + (spin and '\r' or '\n'))
File "C:\Users\delprf2\Anaconda3\lib\encodings\cp1252.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position 1-40: character maps to <undefined>
有没有人如何解决它?提前致谢
解决方案
我是生活进步的作者!
您的系统 python 或终端似乎不接受 unicode 字符。我不知道anaconda,但为什么它使用cp1252?它应该默认接受 utf8。
无论如何,请尝试使用不使用任何花哨字符的主题:
from alive_progress import alive_bar
import time
for x in 3000, 4000, 2000, 0:
with alive_bar(x, theme='ascii') as bar:
for i in range(3000):
time.sleep(0.002)
bar()
请在以下位置找到更多详细信息:https ://github.com/rsalmei/alive-progress 如果您有任何其他疑问,您可以随时在其中打开问题,我会帮助您。
推荐阅读
- javascript - 有输入图像字段,没有任何输入图像
- python - scipy.special.cython_special.eval_genleguerre 的错误评估
- flutter - 将此png保存到颤振的电话画廊
- telegram - Telegram issue:需要进入源频道才能发布到目标频道
- java - 在 RecyclerView 中滑动时不显示 Drawable
- android - 如何根据Android中的某些操作来回更改按钮侦听器
- c++ - 在 C++ 中将空字符串作为函数参数传递的更好方法是什么?
- flutter - Flutter + DIO:如何通过 DIO 在请求中传递 curl 命令的选项?
- css - 单击汉堡包 iPhone 后,Bootstrap 导航栏消失
- angular - Angular:app-routing.module.ts 中路径的目的是什么