pandas 的导入非常慢(Anaconda Python 2.7) [英] Pandas import is very slow (Anaconda Python 2.7)
问题描述
我正在脚本中使用pandas模块.但是,每次我运行脚本时,导入熊猫都需要3到10秒钟的时间.我正在使用Python 2.7的Anaconda软件包,而其他任何模块都没有这个问题.
I am using the pandas module within a script. However, it is taking anywhere from 3-10 seconds to import pandas every time I run the script. I am using the Anaconda package for Python 2.7 and I haven't had have this issue with any other modules.
我在单独的脚本中使用了cProfile,该脚本仅包含"import Pandas"语句.输出的最佳结果如下.
I used cProfile on a separate script that consisted of only an 'import Pandas' statement. Top results from the output are below.
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语句需要我这么长时间,或者我如何更好地诊断/修复正在发生的事情?还有其他人遇到过这个问题吗?
Any ideas why the import pandas statement takes so long for me, or how I might better diagnose/fix what is happening? Has anyone else experienced this issue?
推荐答案
在内部,pandas会导入许多其他内容.这个主题有一个 github问题.
Internally pandas imports a bunch of other stuff. There is a github issue on this topic.
请注意,pytz的导入时间很长(大约是整个大熊猫导入的一半).如果版本为2016.4;版本2016.7和2017.2快得多.您可能要升级您的pytz版本.应该会产生重大影响.
Note that pytz takes a long time to import (about half of the entire pandas import) if it is version 2016.4; version 2016.7 and 2017.2 are much quicker. You might want to upgrade your pytz version; that should have a significant impact.
这篇关于 pandas 的导入非常慢(Anaconda Python 2.7)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!