我正在使用Anaconda的Spyder 4.1.1和W10中的Python 3.7.6。我正在为我的一个项目使用live-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字符。我不知道水蟒,但为什么要使用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如果您还有其他疑问,可以随时在此处提出问题,我们会为您提供帮助。