我在脚本中使用pandas模块。然而,每次运行脚本时,导入熊猫都需要3-10秒的时间。我正在使用Python2.7的Anaconda包,并且我在任何其他模块上都没有遇到这个问题。
我在一个单独的脚本上使用了cProfile,该脚本只包含一个“import Pandas”语句。输出的最高结果如下所示。
C:\Users\*****\AppData\Local\Continuum\Anaconda> python -m cProfile -s cumtime test_pandas_import.py
204229 function calls (199729 primitive calls) in 3.480 seconds
Ordered by: cumulative time
ncalls tottime percall cumtime percall filename:lineno(function)
2 0.216 0.108 3.490 1.745 __init__.py:4(<module>)
1 0.019 0.019 3.482 3.482 test_imports.py:1(<module>)
19 0.155 0.008 1.300 0.068 __init__.py:1(<module>)
1 0.024 0.024 0.895 0.895 config_init.py:11(<module>)
1 0.049 0.049 0.803 0.803 __init__.py:106(<module>)
1 0.024 0.024 0.669 0.669 format.py:2(<module>)
1 0.005 0.005 0.628 0.628 add_newdocs.py:10(<module>)
2 0.029 0.015 0.604 0.302 index.py:2(<module>)
2 0.094 0.047 0.542 0.271 __init__.py:9(<module>)
2 0.092 0.046 0.532 0.266 common.py:1(<module>)
1 0.008 0.008 0.506 0.506 type_check.py:3(<module>)你知道为什么import pandas语句花了我这么长时间吗,或者我如何才能更好地诊断/修复正在发生的事情?还有没有人遇到过这个问题?
发布于 2017-10-24 05:27:34
在国内,熊猫进口了一堆其他的东西。有一个关于这个主题的github issue。
请注意,如果是2016.4版,pytz需要很长时间才能导入(大约是整个pandas导入的一半);2016.7和2017.2版要快得多。您可能想要升级您的pytz版本;这应该会产生重大影响。
发布于 2016-11-21 20:47:46
我怀疑您的DNS已损坏,因为这种延迟更有可能是由失败的DNS请求引起的。尝试使用wireshark或类似的工具,以找出问题所在。
https://stackoverflow.com/questions/34000644
复制相似问题