Skip to content

Wexpect with pyinstaller

Benedek Racz edited this page Apr 9, 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

Upgrade your wexpect to v4.0.0 or higher. This is the first version that uses the new-structured spawn class as the default spawn class.

(You can use the pyinstaller from wexpect v3.3.0, but in this case, you have to choose the new-structured spawn class by setting the WEXPECT_SPAWN_CLASS environment variable to 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