damnever / pigar

:coffee: A tool to generate requirements.txt for Python project, and more than that. (IT IS NOT A PACKAGE MANAGEMENT TOOL)

Home Page:https://damnever.github.io/pigar/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ImportError: No module named 'django.contrib.auth.models'

mslinn opened this issue · comments

When I tried pigar for the first time, I attempted to use it on a django-oscar project.

$ pigar
Traceback (most recent call last):
  File "/var/work/django/oscar/lib/python3.8/site-packages/pigar/core.py", line 406, in is_stdlib
    module_info = imp.find_module(name)
  File "/usr/lib/python3.8/imp.py", line 296, in find_module
    raise ImportError(_ERR_MSG.format(name), name=name)
ImportError: No module named 'django.contrib.auth.models'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/var/work/django/oscar/bin/pigar", line 8, in <module>
    sys.exit(main())
  File "/var/work/django/oscar/lib/python3.8/site-packages/pigar/__main__.py", line 167, in main
    RequirementsGenerator(
  File "/var/work/django/oscar/lib/python3.8/site-packages/pigar/core.py", line 65, in generate
    packages, guess = parse_packages(
  File "/var/work/django/oscar/lib/python3.8/site-packages/pigar/core.py", line 317, in parse_packages
    if is_stdlib(name) or is_stdlib(name.split('.')[0]):
  File "/var/work/django/oscar/lib/python3.8/site-packages/pigar/core.py", line 394, in _wrapper
    checked[name] = func(name)
  File "/var/work/django/oscar/lib/python3.8/site-packages/pigar/core.py", line 410, in is_stdlib
    importlib.import_module(name)
  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/var/work/django/oscar/lib/python3.8/site-packages/django/contrib/auth/models.py", line 2, in <module>
    from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
  File "/var/work/django/oscar/lib/python3.8/site-packages/django/contrib/auth/base_user.py", line 48, in <module>
    class AbstractBaseUser(models.Model):
  File "/var/work/django/oscar/lib/python3.8/site-packages/django/db/models/base.py", line 108, in __new__
    app_config = apps.get_containing_app_config(module)
  File "/var/work/django/oscar/lib/python3.8/site-packages/django/apps/registry.py", line 253, in get_containing_app_config
    self.check_apps_ready()
  File "/var/work/django/oscar/lib/python3.8/site-packages/django/apps/registry.py", line 135, in check_apps_ready
    settings.INSTALLED_APPS
  File "/var/work/django/oscar/lib/python3.8/site-packages/django/conf/__init__.py", line 82, in __getattr__
    self._setup(name)
  File "/var/work/django/oscar/lib/python3.8/site-packages/django/conf/__init__.py", line 63, in _setup
    raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

Is there some way I could run pigar from a Python shell that has all the dependencies set up? I can create such a shell easily with manage.py shell