Pandas导入速度非常慢(Anaconda Python 2.7)

9
我正在使用脚本中的pandas模块。每次运行脚本时,导入pandas需要3-10秒的时间。我正在使用Python 2.7的Anaconda包,但我没有遇到其他任何模块的这个问题。
我在另一个仅包含'import Pandas'语句的脚本上使用了cProfile。以下是输出中的前几个结果。
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>)

有什么想法可以解释为什么我导入 pandas 语句需要这么长时间,或者如何更好地诊断/修复发生的问题?是否还有其他人遇到过这个问题?


发现导入语句问题确实会影响其他模块 - 请参见扩展范围的问题 - TKW
如果您先导入pandas会怎样? - Steven Du
我也遇到了与Anaconda Python 3.5相同的问题,无法导入pandas和matplotlip... - hercules.cosmos
这似乎是我的工作Windows电脑(Anaconda 4.4专业版)的问题。在家里的Windows和Mac上都可以正常工作,因为我对环境有更多的控制。 - Matt Messersmith
2个回答

2

在内部,pandas会导入一堆其他的东西。这个主题有一个关于Github问题

请注意,如果pytz是2016.4版本,它需要很长时间来导入(大约占整个pandas导入的一半)而版本2016.7和2017.2则更快。您可能需要升级您的pytz版本;这应该会有显着影响。


-2
我怀疑你的 DNS 出了问题,因为这种延迟更可能是由于 DNS 请求失败引起的。尝试使用 Wireshark 或类似工具找出它卡在哪里。

6
如果这是原因,那我很好奇为什么每次导入pandas时都需要进行DNS请求... - Mark

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接