Local Testing with Python

This guide explains how to run a simple local web server using Python so you can test static web projects safely on your own computer before uploading changes to a live site.

It was written with this project’s structure in mind, but the same general workflow is useful for many small HTML, CSS, and JavaScript projects.

Important: This page is about running a local test server for the website. It is not a guide to installing or configuring the analyzer itself.

Why Use a Local Server?

  • Test changes safely on your own computer
  • Avoid breaking the live site
  • Preview HTML, CSS, and JavaScript in a browser
  • Develop faster without repeatedly uploading files

A local server creates a simple workflow: edit a file, save it, refresh the browser, and immediately see the result.

Quick Start for This Project

For this project specifically, start the server from the folder above the textAnalysis directory.

cd path/to/the/folder-above-textAnalysis
python -m http.server 8000

If that command does not work, try:

python3 -m http.server 8000

Then open this exact address in your browser:

http://localhost:8000/textAnalysis/index.html

Why This Project Needs That Path

This site uses a base path in the HTML:

<base href="/textAnalysis/">

Because of that, local testing works correctly only when:

  1. the server is started from the parent directory
  2. the page is opened through /textAnalysis/index.html

If the server is started from inside the textAnalysis folder, relative files such as pyscript.toml may fail to load correctly.

Typical Workflow

  1. Open the project folder in your code editor.
  2. Open a terminal in the folder above textAnalysis.
  3. Run python -m http.server 8000.
  4. Open http://localhost:8000/textAnalysis/index.html in the browser.
  5. Edit files.
  6. Save the file.
  7. Refresh the browser to see the changes.

Check if Python Is Installed

Open a terminal and run:

python --version

If that does not work, try:

python3 --version

If Python is installed, a version number should appear.

If Python Is Not Installed

If neither command works, Python may not be installed on your computer. Python is free and can be downloaded from the official Python website:

https://www.python.org/downloads/

On Windows, make sure to check Add Python to PATH during installation.

If Python installs successfully but the python command still does not work, the usual cause is that Python was not added to PATH during installation.

Stopping the Server

Return to the terminal and press:

Ctrl + C

Example Terminal Session

cd your-parent-folder
python -m http.server 8000
Serving HTTP on 0.0.0.0 port 8000...

The following example shows what a working session might look like:

Example of running a Python HTTP server in PowerShell

Common Mistakes and Troubleshooting

Problem: the page loads, but some files fail with a 404 error

Make sure you:

  • started the server from the folder above textAnalysis
  • opened http://localhost:8000/textAnalysis/index.html

Problem: you started the server from inside the wrong folder

The Python server serves files from the directory where it was started. For this project, do not start it from inside textAnalysis.

Use:

cd path/to/the/folder-above-textAnalysis
python -m http.server 8000

Problem: you opened the HTML file directly instead of using localhost

Do not open the file as:

file:///C:/.../index.html

Open it through the local server instead:

http://localhost:8000/textAnalysis/index.html

Problem: port 8000 is already in use

Use another port:

python -m http.server 8080

Then open:

http://localhost:8080/textAnalysis/index.html
Note: This server is for local development and testing only. It should not be used as the production server for the live site.

About “Hot Reload”

This setup does not provide true hot reload. When you make changes to files, you will still need to refresh the browser manually to see updates.

That said, this workflow is still very useful because it lets the project run in a proper web environment and makes testing much faster than repeatedly uploading files to the live site.

In practice: edit a file, save it, refresh the browser, and immediately see the result.

Summary

Running a local Python server makes it easier to test changes safely before uploading them to the live site. For this project, the key detail is to start the server from the folder above textAnalysis and open the page through:

http://localhost:8000/textAnalysis/index.html