Pyinstaller can't find wcwidth "version.json" when running executable

Viewed 326

I'm trying to compile a python script with sklearn, pandas, numpy and igraph, but the Pyinstaller executable doesn't run correctly because it can't find version.json in tmp folder.

FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\Usuario\\AppData\\Local\\Temp\\_MEI106882\\wcwidth\\version.json'
[17248] Failed to execute script pyScript
2 Answers

You'll need to include the wcwidth project directory in your data since it isn't considered a package or a module, its a data file.

In your spec file:

...

import wcwidth


a = Analysis(['main.py'],
             pathex=[],
             binaries=[],
             datas=[
                 (os.path.dirname(wcwidth.__file__), 'wcwidth')                 
                 ],
...

Note: Above I use os.path.dirname(wcwidth.__file__) to dynamically get the directory of wcwidth, but this can just be .venv/lib/site_packages/wcwidth or where-ever it is installed, this was just crucial for CI for me.

Or with --add-data:

pyinstaller --add-data "/path/to/site_packages/wcwidth;wcwidth"

I hit this issue when creating a binary from a virtual environment. It seems installing ipython within the virtual environment is causing this.

Recreating a new virtual environment without ipython seems to overcome the issue.

Related