【问题标题】:My python script runs through my IDE (PyCharm) but it won't run using the Python shell我的 python 脚本通过我的 IDE (PyCharm) 运行,但它不会使用 Python shell 运行
【发布时间】:2013-03-28 01:58:02
【问题描述】:

我有一个使用 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 下却不能运行?

谢谢

【问题讨论】:

    标签: python logging pycharm


    【解决方案1】:

    很可能是因为您的PYTHON_PATH。在 Python IDE 和 shell 中的 Python 中列出 sys.path。寻找 Python 库的不同之处。

    【讨论】:

    • 在python2.x中曾经是sys.path。在 3.x 中是否更改为 os.path
    • 或者仅仅因为错误的pwd(当前工作目录)。
    • 我不认为这是改变。我的错。对不起。
    • os.path 是一个包含各种路径函数的模块。
    • pycharm 中的 sys.path: ['C:\\Program Files (x86)\\JetBrains\\PyCharm 2.7.1\\helpers\\pydev', 'C:\\Python33\\ lib\\site-packages\\distribute-0.6.27-py3.3.egg', 'C:\\Python33\\lib\\site-packages\\pip-1.1-py3.3.egg', 'C :\\Windows\\system32\\python33.zip', 'C:\\Python33\\DLLs', 'C:\\Python33\\lib', 'C:\\Python33', 'C:\\Python33 \\lib\\site-packages', 'C:\\Python33\\lib\\site-packages\\setuptools-0.6c11-py3.3.egg-info', 'C:\\some/path']
    猜你喜欢
    • 1970-01-01
    • 2021-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-15
    • 1970-01-01
    • 1970-01-01
    • 2015-08-30
    相关资源
    最近更新 更多