【发布时间】:2020-04-02 18:10:48
【问题描述】:
我用 Python 编写了一些动画脚本,并使用 Pyinstaller 将其制作为 .exe 文件。该代码在 PyCharm 中运行良好,即仅显示单行进度条。但是,当我打开我认为在 shell 提示符下运行的 .exe 时,它会显示多行。我在 Windows 10 和 Python 3.7 上。这个问题很容易在我的电脑上复制。下面是一个例子。
import matplotlib.pyplot as plt
import matplotlib.animation as ani
import numpy as np
import pandas as pd
from tqdm import tqdm
fig = plt.figure(figsize=(20,12))
ax1 = plt.subplot2grid((2, 2), (0, 0), colspan=2, rowspan=2)
def test(i):
data = np.random.normal(0, 1, i+1)
pd.DataFrame(data).plot(kind='bar', ax=ax1)
Writer = ani.writers['ffmpeg']
writer = Writer(fps=15, metadata=dict(artist='Me'), bitrate=1000)
anim = ani.FuncAnimation(fig=fig, func=test, frames=tqdm(range(10), initial=1, position=0), interval=200, blit=False)
anim.save('textmovie.mp4', writer=writer)
我使用 Pyinstaller 生成 .exe 后,它看起来像这样。
我在这里搜索过类似的问题。似乎人们建议使用 position=0,但这对我不起作用。我是否遗漏了代码中的任何内容?
我知道我可以自己制作进度条,而不是使用 tqdm。但如果可能,我想使用 tqdm,因为它提供了更多信息,例如迭代速度和估计时间。
【问题讨论】:
标签: python shell progress-bar pyinstaller tqdm