1

我有一个使用 logging 模块和 configparser 模块的简短 python 脚本。我在 Win7 下使用 PyCharm 2.7.1 和 Python 3.3。

当我使用 PyCharm 运行我的脚本时 - 它可以工作。这是 PyCharm 控制台的输出:

C:\Python33\python.exe C:/some/path/script.py

Process finished with exit code 0

我在 cmd 中运行相同的命令,这就是我得到的:

C:\>C:\Python33\python.exe C:/some/path/script.py
Traceback (most recent call last):
File "C:/some/path/script.py", line 10
1, in <module>
initLogger()
File "C:/some/path/script.py", line 97, in initLogger
logging.config.fileConfig('RecorderMoverLog.config.ini')
File "C:\Python33\lib\logging\config.py", line 70, in fileConfig
formatters = _create_formatters(cp)
File "C:\Python33\lib\logging\config.py", line 103, in _create_formatters
flist = cp["formatters"]["keys"]
File "C:\Python33\lib\configparser.py", line 942, in __getitem__
raise KeyError(key)
KeyError: 'formatters'

为什么它在 PyCharm 中运行,而在 python shell 下却不能运行?

谢谢

4

1 回答 1

2

这很可能是因为您的PYTHON_PATH. sys.path在您的 Python IDE 和您的 Python in shell 中列出。寻找 Python 库中的差异。

于 2013-04-05T15:22:00.297 回答