Explain Codes LogoExplain Codes Logo

Set up Python simpleHTTPserver on Windows

python
venv
http-server
basic-authentication
Alex KataevbyAlex Kataev·Jan 1, 2025
TLDR

To kick-off a Python HTTP server in a jiffy on a Windows machine, whip out these single-line commands in your Command Prompt; just make sure you're in the directory you'd like to serve:

  • Python 2.x:

    python -m SimpleHTTPServer
    
  • Python 3.x:

    python -m http.server
    

Firing up these commands starts a server on the port 8000 by default. You can reach your files at http://localhost:8000. To spin up the server on a different port, tag on the port number you prefer at the end of the command.

Ensure correct Python version

Confirm you're wielding the right Python version for the command you're about to execute. If you cross wires and run Python 2 commands in Python 3 (or vice versa), brace yourself for errors like "No module named SimpleHTTPServer".

Beware of module mismatches

If you run into the dreaded "No module named SimpleHTTPServer" error under Python 3.x, remember that you're dealing with a case of mistaken identity: the module you're trying to call goes by a different name in Python 3. Ensuring your Python version and module are on first-name terms will help avoid this hiccup.

Customize your stage

  • Adjust the stage size: Make more room with python -m http.server 8080 to expand the stage to port 8080. #MallTakeover
  • Private performances only: Choose your audience by binding to a specific interface like 127.0.0.1 to restrict access to your immediate circle. #VIPsOnly

Dance on a different stage

Have a favorite stage in mind? Navigate to your preferred directory or use the --directory flag (Python 3.7+) to specify where you’d like to strut your stuff. #HomeTurf

python -m http.server --directory /path/to/directory

Stage secure flash mobs

While SimpleHTTPServer isn't the rock of Gibraltar, set up basic authentication or SSL encryption to add a touch of security during your performance, err I mean, development.