python导入应该花这么长时间吗? [英] Should python imports take this long?
问题描述
对于以下命令
%time python test.py
这个脚本上的pre>
,test.py
import numpy as np
来自math import *
import matplotlib.pyplot as plt
import matplotlib.cm as cm
from matplotlib.colors import logNorm
from scipy import stats
我得到输出:
real 0m1.933s
用户0m1.322s
sys 0m0.282s
有什么问题吗?或者这是进口应该花多长时间?
解决方案一些模块在你使用它们时初始化,而其他模块在你启动它时会初始化一切向上。 Matplotlib就是其中一个模块。
由于matplotlib是一个包含大量功能的庞大包,所以我很惊讶这需要很长时间,尽管它可以烦恼。
所以,在回答你的问题时,某些人是。
如果您想要解决问题的解决方案,您可能只想在要使用它时导入matplotlib,或者在加载屏幕/
打印
时输入matplotlib你的计划的开始。For the following command
%time python test.py
on this script, test.py
import numpy as np from math import * import matplotlib.pyplot as plt import matplotlib.cm as cm from matplotlib.colors import LogNorm from scipy import stats
I get the output:
real 0m1.933s user 0m1.322s sys 0m0.282s
Is there something wrong? Or is this how long imports should take?
解决方案Some modules initialize when you use them, while others initialize everything once you start it up. Matplotlib is one of those modules.
Since matplotlib is a huge package that includes a whole lot of functionality, I'm not surprised that it takes this long, although it can get annoying.
So, in answer to your question, yes to some.
If you want a "solution" to your problem, you might want to import matplotlib only when you're going to use it, or have a loading screen /
这篇关于python导入应该花这么长时间吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!