Solved Django Error: That port is already in use. – Mac
I am using Mac os and I get this error message Error: That port is already in use. when I try to run the server.
I am aware of the fact that I can not run the server on the same port before stopping the already running server.
But the issue is, I get the same error even after stopping the server. I tried playing around with this so that I can find the actual problem.
At first, I tried to change the port by running this command: python3 manage.py runserver 7000
, I could also use python3 manage.py runserver 0.0.0.0:7000
The result will be the same.
For me, it worked perfectly and the server ran successfully.
Then I stopped the server and tried to run on the previous port which was 8000.
Now I faced the error for the first time Error: That port is already in use.
Next, I tried to run the project on a new port 6000 and it worked fine.
But now, I was unable to run the server to any of the previous ports that I used earlier. (Not even on 7000 or 8000)
It made me worried this time, as each time I had to run a new port.
Solution:
I searched on the internet and found different ways to fix this. The main object is to kill all the previous processes that occupy the ports.
I find someone saying that you should use sudo lsof -i tcp:8000
if you are using Mac.
But my problem was not only with the 8000 port and killing all the ports one by one was not my cup of tea.
So after running the recommended commands I just restarted my PC and believe me this fixed the error.
So my advice is, just restart your Mac.
But if you still face the issue again then restarting again and again will be annoying and the best solution is to find the PID of that process and kill it.
You can kill it directly from the activity monitor.
Open launchpad of your mac and search for activity monitor. Open the activity monitor.
By running this command: sudo lsof -i tcp:8000
you can find the process id of that port and then just find that in the network section of activity monitor and kill that.
Use force quit option.
Leave a Reply