This article discusses downloading and building PyScript from the source for Ubuntu 20.04 running within Windows WSL. For Linux, skip over the first section covering WSL setup.
This article is written for the Python developer with limited experience building JavaScript/Node.js applications.
Why would you want to do this:
- There are some interesting examples—building from source and running the dev server with the latest PyScript code.
- You want to follow new Pyscript features. By comparing source code changes, you can track what is changing. This includes new features and bugs.
- You simply want the latest version and are willing to work through compatibility issues and bugs.
- You plan to study the source code and possibly contribute to the project.
Setting up WSL
There are a number of Linux distributions available for WSL. I will use Ubuntu 20.04 LTS.
Open an elevated Command Prompt. Install Ubuntu 20.04:
1 |
wsl --install -d Ubuntu-20.04 |
Command output:
1 2 3 4 5 6 7 8 9 |
Installing: Virtual Machine Platform Virtual Machine Platform has been installed. Installing: Windows Subsystem for Linux Windows Subsystem for Linux has been installed. Downloading: WSL Kernel Installing: WSL Kernel WSL Kernel has been installed. Downloading: Ubuntu 20.04 LTS The requested operation is successful. Changes will not be effective until the system is rebooted. |
Reboot your system.
If you are running Windows inside a Hyper-V VM, you might receive this error:
1 |
Error 0x80370102 The Virtual machine could not be started because a required feature is not installed |
This means the installation failed and will need to be repeated. The key is to enable Nested Virtualization.
Open an elevated PowerShell Command Prompt. Replace <VMName>
with the name of the virtual machine.
1 |
Set-VMProcessor -VMName <VMName> -ExposeVirtualizationExtensions $true |
Start the virtual machine.
Repeat the Ubuntu installation if the first attempt failed:
1 |
wsl --install -d Ubuntu-20.04 |
You should have command output similar to:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
Installing, this may take a few minutes... Please create a default UNIX user account. The username does not need to match your Windows username. For more information visit: https://aka.ms/wslusers Enter new UNIX username: jhanley New password: Retype new password: passwd: password updated successfully Installation successful! To run a command as administrator (user "root"), use "sudo <command>". See "man sudo_root" for details. Welcome to Ubuntu 20.04 LTS (GNU/Linux 5.10.16.3-microsoft-standard-WSL2 x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage System information as of Tue May 17 20:13:04 PDT 2022 System load: 0.22 Processes: 8 Usage of /: 0.4% of 250.98GB Users logged in: 0 Memory usage: 1% IPv4 address for eth0: 172.27.65.66 Swap usage: 0% 0 updates can be installed immediately. 0 of these updates are security updates. The list of available updates is more than a week old. To check for new updates run: sudo apt update This message is shown once once a day. To disable it please create the /home/jhanley/.hushlogin file. |
You are now running in the WSL Linux shell. The default shell for Ubuntu is bash. To double-check:
1 |
echo $0 |
Command output:
1 |
-bash |
Update and upgrade the Ubuntu system
1 2 |
sudo apt update sudo apt upgrade -y |
To exit the WSL Linux shell:
1 |
exit |
This returns you to the Windows command prompt.
To return to WSL
1 |
wsl |
If you are running more than one Linux distribution in WSL
1 |
wsl -d Ubuntu-20.04 |
Check the status of WSL
1 |
wsl --status |
Command output:
1 |
Kernel version: 5.10.16 |
Downloading PyScript
The simplest method is to use the git
CLI. Periodically, the PyScript releases tagged versions, which you can download as .zip
or .tar.gz
archives.
Change directories to a location where you want to download the PyScript project. Then run the following command to clone the PyScript repository:
1 |
git clone https://github.com/pyscript/pyscript.git |
Command output:
1 2 3 4 5 6 7 |
Cloning into 'pyscript'... remote: Enumerating objects: 3102, done. remote: Counting objects: 100% (224/224), done. remote: Compressing objects: 100% (128/128), done. remote: Total 3102 (delta 125), reused 172 (delta 93), pack-reused 2878 Receiving objects: 100% (3102/3102), 7.56 MiB | 18.26 MiB/s, done. Resolving deltas: 100% (2052/2052), done. |
Install PyScript dependencies
The version of WSL Ubuntu version of Node.js is out of date. Remove it first:
1 |
sudo apt-get purge --auto-remove nodejs |
Install nvm
to manage node versions:
1 |
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash |
Install the latest LTS version of Node.js:
1 |
nvm install 16 |
Command output
1 2 3 4 5 6 |
Downloading and installing node v16.15.0... Downloading https://nodejs.org/dist/v16.15.0/node-v16.15.0-linux-x64.tar.xz... ####################################################################### 100.0% Computing checksum with sha256sum Checksums matched! Now using node v16.15.0 (npm v8.5.5) |
Change into the PyScript source directory
1 |
cd pyscript/pyscriptjs |
Install the PyScript dependencies:
1 |
npm install |
There are two build options: dev
and build
.
1 |
npm run dev |
After a few minutes, the build completes and the development web server starts.
Open a browser on the host system and go to http://localhost:8080.
Summary
Building PyScript and running the development server is very easy. Once your environment is set up, you can begin to directly work with the source code.
Photography Credit
I write free articles about technology. Recently, I learned about Pexels.com which provides free images. The image in this article is courtesy of cmonphotography at Pexels.
I design software for enterprise-class systems and data centers. My background is 30+ years in storage (SCSI, FC, iSCSI, disk arrays, imaging) virtualization. 20+ years in identity, security, and forensics.
For the past 14+ years, I have been working in the cloud (AWS, Azure, Google, Alibaba, IBM, Oracle) designing hybrid and multi-cloud software solutions. I am an MVP/GDE with several.
Leave a Reply