How to convert a Python Playwright script into an executable App | Playwright with Python

Animesh Singh
4 min readJun 24, 2022

The playwright is a fairly new tool to automate websites and scrape data. It is a better alternative to Selenium as it is faster than selenium, better in terms of adaptation and requires a single pip install without any need to install external web drivers.

Suppose you have a Playwright script written in Python. You can run that in your system very easily because all those dependencies which require to run the program are already on your computer. But what if you developed a project for a client or friend who doesn't know anything about Python and stuff.

In that case, you need to convert your script into an executable file. Usually, it is a fairly simple process with Pyinstaller but in case if you are using Playwright, you need some extra steps to follow.

In this article, I will be showing you how you can convert a Playwright script in to an .exe file.

STEP 1: Making sure your script runs properly.

Run the script final time to check you get correct output.In my case I am getting what I want so I am not showing you that.

My program folder.

STEP 2: Cheking for dependencies and virtual environment.

To keep the size of executable exe minimum , you need to remove all unnecessary libraries installed in virtual env. In case if you haven't have a virtual environment , first create it.

Creating virtual environment:

virtualenv venv

Activating it :

For windows :

venv/Scripts/activate

For linux :

source venv\Scripts\activate

Now install all dependencies one by one including playwright. I am showing the installs for my program .

pip install requestspip install bs4pip install repip install pandaspip install playwrightplaywright install

Note that installing playwright is a two step process.

STEP 3 : Installing auto-py-to-exe tool.

auto-py-to-exe is a GUI tool to convert python program to exe. It uses pyinstaller library and provides user a GUI window to manually add files.

pip install auto-py-to-exe

STEP 4 : Installing a playwright browser.

This is an additional step that you need to perform. You will have a option to choose a web browser of your choice. I am using webkit(safari) because it is smallest in size.

PLAYWRIGHT_BROWSERS_PATH=0 playwright install webkit

Check all the dependencies for last time by pip freeze command.

pip freeze

STEP 4 : Converting program to exe.

Start auto-py-to-exe.

auto-py-to-exe

This is what it looks like.

Select main file in script location. Choose one directory option if you have additional non python files(csv file in case of mine). In additional files select all those files which are required by your program. It can be a python file , image , logo , mp3 , video etc.

Here is what it look like after adding all files.

Notice the command in Current command box. It is the same command you need to perform if you are using pyinstaller in command prompt.

Run the converter. A ‘ Moving project to “directory” complete text will appear if you conversion is successful.

Finally run the main application located in output folder’

Thats all. You have successfully converted a python program to an application.

--

--