{"record":{"id":"6393312951226b39","repo":"HumanSignal/label-studio","slug":"couldn-t-import-django-are-you-sure-it-s-installe","errorCode":null,"errorMessage":"Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?","messagePattern":"Couldn't import Django\\. Are you sure it's installed and available on your PYTHONPATH environment variable\\? Did you forget to activate a virtual environment\\?","errorType":"console","errorClass":"ImportError","httpStatus":null,"severity":"critical","filePath":"label_studio/manage.py","lineNumber":18,"sourceCode":"#!/usr/bin/env python\n\"\"\"This file and its contents are licensed under the Apache License 2.0. Please see the included NOTICE for copyright information and LICENSE for a copy of the license.\"\"\"\n\nimport os\nimport sys\n\nif __name__ == '__main__':\n    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings.label_studio')\n    # os.environ.setdefault('DEBUG', 'True')\n    try:\n        from django.conf import settings\n        from django.core.management import execute_from_command_line\n        from django.core.management.commands.runserver import Command as runserver\n\n        runserver.default_port = settings.INTERNAL_PORT\n\n    except ImportError as exc:\n        raise ImportError(\n            \"Couldn't import Django. Are you sure it's installed and \"\n            'available on your PYTHONPATH environment variable? Did you '\n            'forget to activate a virtual environment?'\n        ) from exc\n    execute_from_command_line(sys.argv)\n","sourceCodeStart":1,"sourceCodeEnd":24,"githubUrl":"https://github.com/HumanSignal/label-studio/blob/0b49e9b53917880baf1dd85d574fe5541a9aafb2/label_studio/manage.py#L1-L24","documentation":"Standard Django bootstrap error re-raised by manage.py when importing django.core.management fails, meaning Django isn't installed or isn't importable in the current Python environment. The original ImportError is chained as __cause__.","triggerScenarios":"Running `python label_studio/manage.py <command>` in an interpreter where the Django package is not installed or not on sys.path.","commonSituations":"Forgot to activate the virtualenv; installed dependencies with a different Python version (pip vs python3 mismatch); running from wrong directory with a bare system Python; partially installed requirements after a failed pip install.","solutions":["Activate the project's virtualenv: source <venv>/bin/activate (or `poetry shell` / `pipenv shell`)","Install dependencies: pip install -r deploy/requirements.txt or pip install label-studio","Run with the venv's interpreter explicitly: <venv>/bin/python label_studio/manage.py <cmd>","Check `pip show django` / `python -c 'import django'` to confirm installability"],"exampleFix":"// before\n$ python label_studio/manage.py runserver  # system python, no Django\n// after\n$ source venv/bin/activate\n$ pip install -r requirements/production.txt\n$ python label_studio/manage.py runserver","handlingStrategy":"validation","validationCode":"import importlib.util, sys\nif importlib.util.find_spec('django') is None:\n    sys.exit('Django not installed; activate your virtualenv and pip install -r requirements.txt')","typeGuard":null,"tryCatchPattern":"try:\n    from django.core.management import execute_from_command_line\nexcept ImportError as exc:\n    sys.stderr.write('Activate your virtualenv and install requirements.\\n')\n    raise SystemExit(1) from exc","preventionTips":["Always activate the virtualenv before running manage.py","Pin and install dependencies with pip install -r requirements.txt","Use the venv interpreter explicitly in scripts/CI: <venv>/bin/python manage.py","Verify environment with `python -c \"import django; print(django.__version__)\"`"],"tags":["python","django","environment","dependency"],"backgroundTag":"django-not-installed","analyzedSha":"0b49e9b53917880baf1dd85d574fe5541a9aafb2","analyzedAt":"2026-08-29T00:39:52.578Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}