Python - 脚本在一个文件夹中执行时抛出错误。但不是在另一个执行时

Python - Script throws error when executed in one folder. But not when executed in another

每当我执行以下脚本时: https://bitbucket.org/pedro_stanaka/flock-log-parser/src/1340cdb7f873f158d3778aec445e4e37ee5f2a32/main.py?fileviewer=file-view-default

在其原始文件夹中(在项目中)我收到以下错误:

Traceback (most recent call last):
   File "main.py", line 7, in <module>
   from matplotlib.backends.backend_pdf import PdfPages
[...] 
File "/usr/lib/python3.4/unittest/case.py", line 253, in <module>
class _CapturingHandler(logging.Handler):
AttributeError: 'module' object has no attribute 'Handler'

但是当我将脚本(和 JUST 脚本)复制到我计算机中的另一个文件夹时,运行 它使用相同的命令行工作。

    python3.4 main.py

为什么会这样?这种行为有任何解释吗? 我非常想保持不变 folder/project.

我尝试设置 PYTHONPATH,但效果不佳。

class _CapturingHandler(logging.Handler):
AttributeError: 'module' object has no attribute 'Handler'

Python 的 logging 模块将始终具有此属性 Handler,因此我可以猜测您在同一目录中还有另一个名为 logging.py 的文件.将该模块重命名为与核心模块不冲突的其他名称。