Python ValueError: Unable to configure handler 'file': [Errno 2] No such file or directory:

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39101488/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 21:52:53  来源:igfitidea点击:

ValueError: Unable to configure handler 'file': [Errno 2] No such file or directory:

pythondjangopycharm

提问by Deon Van Zyl

I am very new to Python and Django and is currently busy learning myself through tutorials on www.djangoproject.com. I am using PyCharm and working on OS X El Capitan. I have imported a project from github and created a virtual environment for the project interpretor based on Python 3.5.1. In the vm I installed django.

我对 Python 和 Django 非常陌生,目前正忙于通过 www.djangoproject.com 上的教程自学。我正在使用 PyCharm 并在 OS X El Capitan 上工作。我从github导入了一个项目,并为基于Python 3.5.1的项目解释器创建了一个虚拟环境。在 vm 中我安装了 django。

I then activated the vm.

然后我激活了虚拟机。

Now.. i started by trying to execute simple commands in the terminal like python manage.py startapp deonappand python manage.py runserverbut each time I get an error which I pasted below.. What did I miss? I cannot seem to find the /log/ directory?

现在..我开始尝试在终端中执行简单的命令,比如 p ython manage.py startapp deonapppython manage.py runserver但是每次我得到一个错误,我粘贴在下面..我错过了什么?我似乎找不到 /log/ 目录?

Traceback (most recent call last):
  File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/logging/config.py", line 558, in configure
    handler = self.configure_handler(handlers[name])
  File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/logging/config.py", line 731, in configure_handler
    result = factory(**kwargs)
  File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/logging/__init__.py", line 1008, in __init__
    StreamHandler.__init__(self, self._open())
  File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/logging/__init__.py", line 1037, in _open
    return open(self.baseFilename, self.mode, encoding=self.encoding)
FileNotFoundError: [Errno 2] No such file or directory: '/Users/deon/Documents/PyCharmProjects/Developments/deonproject/log/debug.log'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/deon/Documents/PyCharmProjects/Developments/deonproject/venv/lib/python3.5/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
    utility.execute()
  File "/Users/deon/Documents/PyCharmProjects/Developments/deonproject/venv/lib/python3.5/site-packages/django/core/management/__init__.py", line 341, in execute
    django.setup()
  File "/Users/deon/Documents/PyCharmProjects/Developments/deonproject/venv/lib/python3.5/site-packages/django/__init__.py", line 22, in setup
    configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
  File "/Users/deon/Documents/PyCharmProjects/Developments/deonproject/venv/lib/python3.5/site-packages/django/utils/log.py", line 75, in configure_logging
    logging_config_func(logging_settings)
  File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/logging/config.py", line 795, in dictConfig
    dictConfigClass(config).configure()
  File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/logging/config.py", line 566, in configure
    '%r: %s' % (name, e))
ValueError: Unable to configure handler 'file': [Errno 2] No such file or directory: '/Users/deon/Documents/PyCharmProjects/Developments/deonproject/log/debug.log'

回答by Dmitry Torba

You do not have path to a log file for some reason (/Users/deon/Documents/PyCharmProjects/Developments/deonproject/log). Make sure that all directories exist (if no, create them) and create an empty debug.loglog file (just in case).

由于某种原因,您没有日志文件的路径(/Users/deon/Documents/PyCharmProjects/Developments/deonproject/log)。确保所有目录都存在(如果不存在,则创建它们)并创建一个空的debug.log日志文件(以防万一)。

What happens is there is some problem with your code happening. Handler catches this error to save it to your log file so that you can analyze it. However, the path to log file it is trying to open does not exist. Thus, exception occures during handling of another exception.

发生的情况是您的代码发生了一些问题。处理程序捕获此错误以将其保存到您的日志文件中,以便您可以对其进行分析。但是,它尝试打开的日志文件的路径不存在。因此,在处理另一个异常的过程中会发生异常。