This is the first time that I have used pyinstaller to build an .exe of my .py on a windows machine. I have successfully generated the .exe, but when I run the code it does not produce the .csv file that my code should produce.
On a side note, when I run my script within the IDE it successfully generates the .csv that I expect it to. The bottom is the part of my code that should generate the output.
writer = pd.ExcelWriter('Desired_Output.xlsx', engine= 'xlsxwriter')
df3.to_excel(writer, sheet_name='Output')
#Get the xlsxwriter workbook and worksheet objects
workbook = writer.book
worksheet = writer.sheets['Output']
# Add some cell formatting and save the contents
format1 = workbook.add_format({'left': 1, 'right': 1, 'top': 1, 'bottom': 1, 'bg_color': 'gray' })
format2 = workbook.add_format({'bottom': 1})
format3 = workbook.add_format({'bottom': 1, 'font_size': 7, 'bg_color': '#98FB98'})
format4 = workbook.add_format({'right': 1, 'bottom': 1})
worksheet.set_column('B:B', 12, format1)
worksheet.set_column('C:N', 8, format2)
worksheet.set_column('L:L', 6, format3)
worksheet.set_column('N:N', 8, format4)
writer.save()
When run in the command prompt I get the error
No module xlsxwriter, but when I try to run the pip install it says that I am already running xlsxwriter
It is possible that the program is not running correctly because the .exe was not bundled correctly, or perhaps the application may be closing because it is unable to import a package or find an external file, which prevents your application from launching. To view the error messages associated with running your executable, run the .exe file from the command prompt: /path/to/app/dist/MyApp.exe
(in Command Prompt). This will allow you to observe any errors that may exist after the app was bundled. If the program does fail during an import statement, you may need to add a package to the hiddenimports
list in the .spec file.
It is difficult for us to diagnose this problem without more information, but perhaps the output displayed in the command prompt will provide some more information.
**Edit: ** Your edit suggests that at least one module was not included in the bundled app.
To add modules to the .spec file: Once you run pyinstaller, a .spec file will be generated in the directory containing your .py file. You can open this .spec file and add modules to the list named hiddenimports
. For example: hiddenimports = ['xlsxwriter', 'any_other_modules']
. Once you've updated your .spec file, run the pyInstaller command again with the .spec file: pyinstaller --some_options my_app.spec
--or--
To add modules at the command prompt: Run pyinstaller with the hiddenimports
option: pyinstaller --hidden-import xlsxwriter my_app.py
See the docs for more information.