mac error that port is already in use

  1. Open the terminal on your Mac.

  2. Use the following command to identify the process ID (PID) that is using the port:

lsof -i :<port_number>

Replace <port_number> with the actual port number that is in use.

  1. Note the PID from the output.

  2. Terminate the process using the identified PID with the following command:

kill -9 <PID>

Replace <PID> with the actual process ID obtained in step 3.

  1. Retry running your Django development server. If the issue persists, choose an alternative port for your Django application:
python manage.py runserver <new_port_number>

Replace <new_port_number> with the desired port number.

  1. If you need to find an available port dynamically, use the following command:
python -c "import socket; s=socket.socket(); s.bind(('', 0)); print(s.getsockname()[1]); s.close()"

This will print an available port number. Use it when starting your Django development server.