python导入的奇怪行为

时间:2017-02-12 21:51:35

标签: python python-3.x anaconda

我遇到了python导入的奇怪行为。 Python版本是3.5.2。看起来如果一个名称与一些标准模块名称相同的子包(如日志记录) - 它会因某种原因而影响它。

这是一个玩具示例:

export PYTHONPATH=$PYTHONPATH:/home/areshytko/src

src/bar/__init__.py - 空

src/bar/main.py

import pandas

if __name__ == "__main__":
   print("success")

src/bar/logging/__init__.py - 空

python bar / main.py

Traceback (most recent call last):
  File "bar/main.py", line 2, in <module>
    import pandas
  File "/home/areshytko/anaconda3/lib/python3.5/site-packages/pandas/__init__.py", line 13, in <module>
    __import__(dependency)
  File "/home/areshytko/anaconda3/lib/python3.5/site-packages/numpy/__init__.py", line 142, in <module>
    from . import add_newdocs
  File "/home/areshytko/anaconda3/lib/python3.5/site-packages/numpy/add_newdocs.py", line 13, in <module>
    from numpy.lib import add_newdoc
  File "/home/areshytko/anaconda3/lib/python3.5/site-packages/numpy/lib/__init__.py", line 8, in <module>
    from .type_check import *
  File "/home/areshytko/anaconda3/lib/python3.5/site-packages/numpy/lib/type_check.py", line 11, in <module>
    import numpy.core.numeric as _nx
  File "/home/areshytko/anaconda3/lib/python3.5/site-packages/numpy/core/__init__.py", line 58, in <module>
    from numpy.testing.nosetester import _numpy_tester
  File "/home/areshytko/anaconda3/lib/python3.5/site-packages/numpy/testing/__init__.py", line 10, in <module>
    from unittest import TestCase
  File "/home/areshytko/anaconda3/lib/python3.5/unittest/__init__.py", line 59, in <module>
    from .case import (TestCase, FunctionTestCase, SkipTest, skip, skipIf,
  File "/home/areshytko/anaconda3/lib/python3.5/unittest/case.py", line 273, in <module>
    class _CapturingHandler(logging.Handler):
AttributeError: module 'logging' has no attribute 'Handler'

0 个答案:

没有答案