Ausgabe
Ich bin sehr neu in Python und Django und lerne derzeit fleißig durch Tutorials auf www.djangoproject.com. Ich verwende PyCharm und arbeite an OS X El Capitan. Ich habe ein Projekt von github importiert und eine virtuelle Umgebung für den Projektinterpreter auf Basis von Python 3.5.1 erstellt. In der VM habe ich Django installiert.
Ich habe dann die VM aktiviert.
Jetzt habe ich versucht, einfache Befehle im Terminal wie p auszuführen, ython manage.py startapp deonapp
und python manage.py runserver
jedes Mal erhalte ich einen Fehler, den ich unten eingefügt habe. Was habe ich verpasst? Ich kann das Verzeichnis /log/ nicht finden?
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'
Lösung
Sie haben aus irgendeinem Grund keinen Pfad zu einer Protokolldatei (/Users/deon/Documents/PyCharmProjects/Developments/deonproject/log). Stellen Sie sicher, dass alle Verzeichnisse vorhanden sind (wenn nein, erstellen Sie sie) und erstellen Sie eine leere debug.log
Protokolldatei (nur für den Fall).
Was passiert, ist, dass ein Problem mit Ihrem Code auftritt. Der Handler fängt diesen Fehler ab, um ihn in Ihrer Protokolldatei zu speichern, damit Sie ihn analysieren können. Der Pfad zur Protokolldatei, die geöffnet werden soll, ist jedoch nicht vorhanden. Daher tritt eine Ausnahme während der Behandlung einer anderen Ausnahme auf.
Beantwortet von – Dmitry Torba
Antwort geprüft von – David Goodson (FixError Volunteer)