Django运行django-admin.py报错:ImportError: No module named deltatest.settings求助
Hey there! Let's walk through some targeted fixes for this issue—since you’ve already tried reinstalling Django, we can focus on the most likely culprits that often slip through a standard reinstall:
1. Check for a lingering DJANGO_SETTINGS_MODULE environment variable
The error mentions deltatest.settings, which suggests your shell might be set to look for this specific settings module no matter where you run django-admin.
Check the variable:
- On Linux/Mac, run this in your terminal:
echo $DJANGO_SETTINGS_MODULE - On Windows Command Prompt:
echo %DJANGO_SETTINGS_MODULE%
If the output is
deltatest.settings, that’s the problem. django-admin is trying to load a settings module from a project that isn’t your current context.- On Linux/Mac, run this in your terminal:
Fix it:
- Linux/Mac:
unset DJANGO_SETTINGS_MODULE - Windows:
set DJANGO_SETTINGS_MODULE=
Try running
django-admin.pyagain after this.- Linux/Mac:
2. Verify your working directory
If you’re running django-admin.py from inside the deltatest project directory (or a subdirectory), Django might be confused into thinking it’s supposed to load that project’s settings—even if you’re trying to create a new project.
- Fix it:
Navigate to an empty directory (one that isn’t a Django project) and run yourdjango-admin.pycommand there. For example:cd ~/Desktop/empty-folder django-admin.py startproject my_new_project
3. Resolve Python environment conflicts
Sometimes reinstalling Django doesn’t fix the issue if you’re using a different Python environment than the one where Django is installed (e.g., system Python vs. a virtual environment, or multiple Python versions).
Check your environment:
Run these commands to confirm which Python and Django you’re using:# Which Python are you running? which python # Linux/Mac where python # Windows # What Django version is installed here? python -m django --versionIf the Django version doesn’t match what you installed, you’re using the wrong environment.
Use the module-based command instead:
Instead of runningdjango-admin.pydirectly, try calling Django via Python’s module system—it’s more reliable for environment consistency:python -m django startproject my_new_project
4. Clean up residual project files (rare but possible)
If you’ve worked with the deltatest project recently, there might be leftover cache or configuration files that are confusing Django:
- Delete any
__pycache__folders in your current directory or thedeltatestproject. - Double-check your Python
site-packagesdirectory to ensure there are no stray files related todeltatest(unlikely if you reinstalled Django, but worth a quick check).
Start with steps 1 and 2 first—those are the most common causes of this exact error. Let me know if any of these fix it!
内容的提问来源于stack exchange,提问作者Z.Ben

