有人可以帮助我理解为什么python的日志记录模块在导入时创建StreamHandler,但仅在某些发行版中创建吗?很奇怪..(注意:发生在任何python3上)
在Mac上
Python 3.5.6 (default, Dec 19 2019, 14:59:39)
[GCC 4.2.1 Compatible Apple LLVM 11.0.0 (clang-1100.0.33.8)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import logging
>>> logging.getLogger().handlers
[<logging.StreamHandler object at 0x108fc2630>]
Linux:
Python 3.7.4 (default, Jan 3 2020, 19:27:19)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import logging
>>> logging.getLogger().handlers
[]
>>>
我似乎找不到关于这种行为差异的任何解释!
编辑:
更多调查表明,virtualenv
中安装的某些模块导致此行为不匹配。我用相同的python解释器创建了一个新的,并且没有处理程序。我正在尝试调查哪个模块似乎导致了这种情况。