Search code examples
pythonpyinstaller

Adding an individual file to PyInstaller


I'm attempting to use PyInstaller with pyarmor. I'm using pyarmors "super mode", which creates pytransform.pyd at the root of my module.

For the record, I'm not using a spec file, instead I'm doing it python with PyInstaller.__main__.run(args). Not sure if that makes any difference.

Directory structure:

c:/dist/
    module/
        *.py  # Obfuscated code
    data/
        stuff.json
    pytransform.pyd

I'm already using --add-data C:/dist/module;module and --add-data C:/dist/data;data to include most of the necessary files, however I'm struggling with pytransform.pyd.

If I use --add-data C:/dist/pytransform.pyd;pytransform.pyd, I get this error when running the built executable. It looks like it's assuming it's a directory.

pytransform.pyd\pytransform.pyd could not be extracted!
fopen: No such file or directory

If I use --add-binary C:/dist/pytransform.pyd;pytransform.pyd, I get this error when building:

FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\Peter\\AppData\\Roaming\\pyinstaller\\bincache00_py37_64bit\\pytransform.pyd\\pytransform.pyd'

I checked the bincache folder, and it actually contains pytransform.pyd, so it's halfway there.

How can I add just a single file to the executable?


Solution

  • It worked when adding it as a hidden import, using --hidden-import=pytransform.

    I would still be interested knowing why the --add-data and --add-binary didn't work though.