0

I am getting errors when trying to freeze a script that imports openpyxl - and no .exe is generated. The same errors if the script contains only 'import openpyxl'.

I am currently using Python 3.7.1, Pyinstaller 3.6, and Openpyxl 2.5.12. I freeze the script by copying it into the Anaconda scripts folder and then using powershell to summon pyinstaller to freeze the script into a single .exe. I have successfully frozen some other scripts using this method.

Searching for answers online showed that openpyxl doesn't like being frozen, but a number of places seemed to say that they had managed to find workarounds.

I have tried a number of the solutions suggested, including placing the hook file in the directory and calling it out as a hidden import in the powershell window: .\pyinstaller --hidden-import=openpyxl --onefile -w 'script.py'

However, nothing I have found has worked. My script is rather large and I would prefer to not have to re-write it using a different excel module. Is there a way I can freeze my script to allow others to use it without having to install python?

flametahu
  • 13
  • 2

1 Answers1

-1

Try using cx_freeze it often gives less errors. Save the file names as given below and run the build.bat file

setup.py

import cx_Freeze
from cx_Freeze import * 

setup (
    name = "give_name",
    options = {'build_exe':{'packages': ['package_name']}},
    executables = [
        Executable(
            "give_name.py", 

        )

    ]

)

build.bat

py setup.py build
rishi
  • 643
  • 5
  • 21
  • Is this definitely applicable to PyInstaller? – Neil Feb 12 '23 at 15:42
  • @Neil cx_freeze is not the same as pyinstaller. At the time of writing this answer, cx_freeze seemed to provide more control over how to package the python code. – rishi Feb 16 '23 at 10:26
  • Thanks. I had suspected info on cx_freeze might not be directly applicable to the question about PyInstaller. Good to know it's an alternative though. – Neil Feb 19 '23 at 21:10