Background Information

Background Information #

This page shows some information you might need, but isn’t specific to Learning PyScript. The lessons assume you know a bit of HTML, a bit of Python, and generally how things work, but we all have different background knowledge. If something is missing from here, let me know! Check out contact information in the footer (bottom) of each page.

Making HTML Files #

HTML files are just normal text files, except they contain code for HTML, and they have a .html extension, instead of .txt. If you run Windows, you have probably used Notepad to write a text file, but I strongly recommend using anything else. Notepad has some weird deficiencies in it, that other editors don’t have.

Some lightweight options include:

If you do not have admin writes to your computer, Sublime Text has a portable version, i.e. no installation needed. You could also install Anaconda Python in user mode, and then run Jupyter Lab, using it to create the files - however this might be a bit overkill. If you already do some python though, you might already have this setup.

When creating your HTML files, remember to save with a .html extension, for example myfile.html. Depending on the editor, you might need to use Save As… to do this. In addition, make sure that when you Save As, you select HTML (or, if that doesn’t exist, Any file) from the save window. Otherwise your file might be called myfile.html.txt and not work!

Running a simple local web server #

You will need serve your files to run them - just opening them with a web browser will run into problems. Modern browsers don’t like running local files with the permissions needed for PyScript to run.

To run a web server, open a Python console (install Python with Anaconda, and then open from your Start Menu), and run:

cd your_project_folder
python -m http.server

The command will run, and tell you to open your browser and go to a specific URL, usually http://127.0.0.1:8080 (although the details here might be different to you).

If you know a different way to run a webserver, you are welcome to do that - you don’t need to run a python web server to run PyScript. PyScript files are just normal, static HTML files - literally every web server can serve this content.