Skip to content

Wexpect with pyinstaller

Benedek Racz edited this page Feb 23, 2020 · 3 revisions

Intro

The legacy wexpect was compatible with py2exe, but the latest version of py2exe has been released in 2014! So based on several requests (see #12) the pyinstaller support has been implemented in version v3.3.0 (While the py2exe support has been removed.)

How to use Wexpect with pyinstaller

Version

First, be sure, that you use wexpect v3.3.0 or higher.

Use new-structured wexpect

First, the legacy-wexpect does not support pyinstaller (and it will not support in the future.) So switch to one fo the new-structured wexpect, by setting the WEXPECT_SPAWN_CLASS environment variable to SpawnPipe. Enter set WEXPECT_SPAWN_CLASS=SpawnPipe in Windows' CMD, or writeos.environ['WEXPECT_SPAWN_CLASS']=SpawnPipe in python before importing wexpect. After this modification, please test your code without pyinstaller, because some feature has not been implemented in SpawnPipe.

Create wexpect executable

Because wexpect uses a console-reader subprocess to manipulate the child's console, you have to create and place this, console-reader or wexpect executable beside your application. To create wexpect executable download/clone wexpect from GitHub. There is a wexpect.spec pyinstaller spec file in the repo's folder. Start pyinstaller with this file: pyinstaller wexpect.spec. This will create the console-reader executable. The freeze of the wexpect has to run once per wexpect versions. This console-reader executable must be delivered with your script's executable.

Create your executable

Finally, freeze your script with pyinstaller with pyinstaller your_script.py. Place wexpect's bundle beside your scrip's bundle.

dist
 ├─wexpect
 │  ├─ ...
 │  ├─ wexpect.exe
 │  └─ ...
 └─your_script
    ├─ ...
    ├─ your_script.exe
    └─ ...
Clone this wiki locally