Coursera学Python后尝试Django全新安装,runserver报Traceback求助
Hey there, let’s work through this runserver issue you’re hitting while practicing Python from your Coursera specialization. Since reinstalling Django didn’t fix things, here are some targeted steps to diagnose and resolve the problem:
Verify your environment setup
First, double-check that you’re working in the correct Python environment. Runpython --versionto confirm it’s 3.6, thenpip listto ensure Django 2.0.2 is installed in that environment. If you’re using a virtual environment, make sure it’s activated properly (on Windows, that’svenv\Scripts\activatein your project directory).Confirm your working directory
Make sure you’re running therunservercommand from the root directory of your Django project—the same folder that containsmanage.py. If you’re in a subfolder, Django won’t find the necessary configuration files, leading to a traceback.Dig into the exact traceback details
The traceback message holds critical clues! For example, if it’s aModuleNotFoundError, you might be missing a project dependency (not just Django). If it’s an import error related to your project’s settings, checksettings.pyfor typos or missing configurations. Even noting the last line of the error can help narrow things down.Clear cached files
Corrupted.pycfiles or cache directories can cause unexpected errors. Delete any__pycache__folders in your project and virtual environment, then try runningpython manage.py runserveragain.Test with a fresh Django project
To rule out project-specific issues, create a new test project with:django-admin startproject test_project cd test_project python manage.py runserverIf this works, your original project likely has a corrupted file (like a misconfigured
settings.pyor missing app) that needs fixing.Specify the Python version explicitly
On Windows, multiple Python versions can sometimes conflict. Try running the server with the exact Python 3.6 executable:py -3.6 manage.py runserver
Let me know if any of these steps resolve the issue, or if you can share the full traceback message—we can narrow it down further!
内容的提问来源于stack exchange,提问作者Anders Erixon

