Getting the pegen examples/visualization to work.

In the previous blogpost, I linked to the code that Guido used to visualize the PEG parser now used in CPython 3.9. The code lives in the GitHub repository - pegen.

I use Windows as my daily driver and right off the bat, this is a problem because the visualizer uses the curses standard library package - which only works on Linux/Mac OS by default. There are apparently Python packages I can install to get it to work on Windows but I didn't try that approach. A brief search on PyPI led me to the windows-curses package, which might be the solution.

I switched to the Ubuntu WSL I have setup on my Windows machine.

Once on Ubuntu, I needed to install Python. Specifically, I wanted to install Python 3.9. For that, I had to add the deadsnakes ppa to the apt repository list. Once I did that, I needed to install Python3.9-dev and Python3.9-venv. venv to be able to create a virtual environment and install the necessary packages. Python3.9-dev because one of the requirements needed the development headers for CPython.

The requirements are listed in the requirements-text file in the aforementioned GitHub repository.

Finally, I could now run the visualizer using

python -m storyX.driver

where X is 3-7. Note that the story1 and story2 packages do not have the driver script that creates the visualization.

The story3 package contains an example of how the visualization looks.



Popular posts from this blog

Farewell to Enthought

Arxiv author affiliations using Python

Elementary (particle physics), my dear Watson