Django执行manage.py runserver启动失败求助
Hey there! I remember how frustrating it was when I first started with Django and hit random runserver errors—let’s walk through the most common fixes, starting with your question about the 8000 port.
First: Check if Port 8000 is Occupied
Absolutely, port conflicts are a super common culprit. Here’s how to check and fix it:
- On Windows (since you’re using WAMP), open Command Prompt and run:
If you see a result, note the PID number at the end. Open Task Manager, go to the Details tab, find that PID, right-click and end the process.netstat -ano | findstr :8000 - If you don’t want to kill the existing process, just run the server on a different port instead:
python manage.py runserver 8001
Other Critical Troubleshooting Steps
Port issues are just one possibility—let’s cover the other most likely problems:
Make sure your virtualenv is activated
You need to be inside your virtual environment when runningrunserver. Check if your command prompt has(venv)at the start (or whatever you named your virtualenv). If not:- Windows:
venv\Scripts\activate - macOS/Linux:
source venv/bin/activate
If you skip this, you’re probably using your system’s Python which might not have Django installed.
- Windows:
Verify Django is installed in your virtualenv
With the virtualenv activated, run:pip listLook for Django in the list. If it’s missing, install it with:
pip install djangoEnsure you’re in the right directory
You must runrunserverfrom the same folder where yourmanage.pyfile lives. If you’re in a subfolder (likemyapp/instead ofmyproject/), you’ll get an error saying it can’t findmanage.py.Read the actual error message carefully
This is the most important step! The error traceback will tell you exactly what’s wrong. For example:- If it’s a database error: Since you have WAMP, if you switched from SQLite to MySQL, make sure WAMP’s MySQL service is running, you’ve installed
mysqlclientviapip, and yoursettings.pyhas the correctDATABASESconfiguration. - If it’s a syntax error: Check the file and line number mentioned in the traceback (usually in
models.pyorviews.py) for typos.
- If it’s a database error: Since you have WAMP, if you switched from SQLite to MySQL, make sure WAMP’s MySQL service is running, you’ve installed
内容的提问来源于stack exchange,提问作者Sebastian Guzman

