Deon Van Zyl
Deon Van Zyl

Reputation: 519

Django: ValueError: Unable to configure handler - [Errno 2]

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 interpreter based on Python 3.5.1. In the vm I installed django.

I then activated the vm.

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

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'

Upvotes: 1

Views: 22014

Answers (4)

Block2busted
Block2busted

Reputation: 47

Traceback says, that it's no "log" directory.

  1. Create directory with name log in path /Users/deon/Documents/PyCharmProjects/Developments/deonproject/
  2. Create empty file .gitkeep
  3. After creating .gitkeep file, push it to GitHub

Upvotes: 0

SirSaleh
SirSaleh

Reputation: 1604

Other answers can be true in most of cases, But In my case log directory was created, But log dir had permission issue to my user. simply using chown to my user (my case www-data) solved the problem.

(In my case):

sudo chown www-data:www-data /var/log/django/

use your username:user-group instead of www-data:www-data and your log dir instead of /var/log/django/.

Upvotes: 0

chihokyo
chihokyo

Reputation: 11

you can add this in setting.py

LOG_PATH = os.path.join(BASE_DIR, 'log')

or

if not os.path.join(LOG_PATH):
    os.mkdir(LOG_PATH)

Upvotes: 1

Deon Van Zyl
Deon Van Zyl

Reputation: 519

I managed to fix it. The log directory was not created because it was excluded in the .gitignore file. I completely forgot to look what was excluded :). I created the directory manually and now it passed the error. Deon

Upvotes: 5

Related Questions