Pycharm complain about django

Answered

I have following stacktrace on every app run from Pycharm:

/usr/bin/python3.6 /opt/pycharm-professional/helpers/pydev/pydevconsole.py --mode=client --port=39337
import sys; print('Python %s on %s' % (sys.version, sys.platform))
import django; print('Django %s' % django.get_version())
sys.path.extend(['some path list'])
if 'setup' in dir(django): django.setup()
import django_manage_shell; django_manage_shell.run("")
Python 3.6.5 (default, Apr 23 2019, 17:24:47)
Type "copyright", "credits" or "license" for more information.
IPython 5.4.1 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
PyDev console: using IPython 5.4.1
Python 3.6.5 (default, Apr 23 2019, 17:24:47)
[GCC 8.2.0] on linux
Traceback (most recent call last):
File "/usr/lib64/python3.6/site-packages/IPython/core/interactiveshell.py", line 2882, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-1-e9aaebe7a1a7>", line 4, in <module>
import django; print('Django %s' % django.get_version())
File "/opt/pycharm-professional/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
ModuleNotFoundError: No module named 'django'

But I don't use django anywhere in my project... otherwise this does not affect work, the apps are running, but just generate noisy output... 

When I install django its even more verbose:

import sys; print('Python %s on %s' % (sys.version, sys.platform))
import django; print('Django %s' % django.get_version())
sys.path.extend(['some paths'])
if 'setup' in dir(django): django.setup()
import django_manage_shell; django_manage_shell.run("some path")
Python 3.6.5 (default, Apr 23 2019, 17:24:47)
Type "copyright", "credits" or "license" for more information.
IPython 5.4.1 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
PyDev console: using IPython 5.4.1
Python 3.6.5 (default, Apr 23 2019, 17:24:47)
[GCC 8.2.0] on linux
Django 2.2.1
Traceback (most recent call last):
File "/usr/lib64/python3.6/site-packages/IPython/core/interactiveshell.py", line 2882, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-1-e9aaebe7a1a7>", line 6, in <module>
if 'setup' in dir(django): django.setup()
File "/home/zangetsu/.local/lib64/python3.6/site-packages/django/__init__.py", line 19, in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
File "/home/zangetsu/.local/lib64/python3.6/site-packages/django/conf/__init__.py", line 79, in __getattr__
self._setup(name)
File "/home/zangetsu/.local/lib64/python3.6/site-packages/django/conf/__init__.py", line 64, in _setup
% (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting LOGGING_CONFIG, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configu

Can I escape this without Django at all?

1 comment
Comment actions Permalink

Hi, do you have Django support enabled in Settings | Languages & Frameworks | Django? Make sure there is no Django imports in Settings | Build, Execution, Deployment | Console | Python Console | Starting script. By default starting script is

import sys; print('Python %s on %s' % (sys.version, sys.platform))
sys.path.extend([WORKING_DIR_AND_PYTHON_PATHS])
0

Please sign in to leave a comment.