Opening a text file and writing some of its contents to an xlsx file in the current working directory with a .exe

0

I have a script, called BLRP2Excel.py, that takes a text file called BLRP.txt in the same directory as the script, and writes some of it's content to a .xlsx file called 'Computer Data.xlsx.' The idea is to use PyInstaller (Python 3.5) to turn my script into a .exe that will run on any Windows PC, where BLRP.txt is in the same directory as the .exe, and to output 'Computer Data.xlsx' to, let's say, the same directory. The script does exactly what it's supposed to when run in PyCharm.

Here are the relevant pieces of my code:

import os
import xlsxwriter

cwd = os.getcwd()

workbook = xlsxwriter.Workbook(cwd + "\\" + 'Computer Data.xlsx')

"rest of my code"

with open(cwd + "\\" + 'BLRP.txt') as my_file:

"rest of my code"

I installed PyInstaller both in my virtual environment and directly from a command prompt in the PATH folder where my project is, opened a command prompt in the same directory as BLRP2Excel.py, and ran:

pyinstaller BLRP2Excel.py

This successfully created a pycache, build, and dist folder in the same directory as my script. I tossed my BLRP.txt into the dist folder and ran the BLRP2Excel.exe, and...

nothing happened except a flash of the command prompt.

What went wrong?

Johnny Apple

Posted 2017-09-02T22:15:53.420

Reputation: 111

Make the logic BEFORE you convert to an exe keep the command console open so you see the output and then convert that to an EXE that also does the same thing so you can troubleshoot. Once you do that, report back the results of this with an [edit] so no one needs to guess to help you out and actually you might get something more meaningful than a quick flash to actually give you some clue to figure out on your own. Just go back to the basic with this stuff and don't overthink; the one way to tell is to see the output/result to have that display and stay with the logic, then convert and try. – Pimp Juice IT – 2017-09-03T00:15:39.113

If it still flashes after that, then look over app event log and be sure you code it to log to a file or something or else see if Windows OS is blocking it, etc. What you running, Windows XP, Vista, 7, 10 or what? – Pimp Juice IT – 2017-09-03T00:16:54.720

Answers

1

I tossed my BLRP.txt into the dist folder and ran the BLRP2Excel.exe, and... nothing happened except a flash of the command prompt.

First, your program is producing some kind CLI output, meaning its generating a command window which closes automatically if not already open (the command prompt flash).

Since your program isn't working correctly, this is probably the specific error being encountered. Open a command window in the same directory as your .exe file (Shift -> Right-Click -> "Open command window here...") and use that to run the .exe e.g.

C:\some\dir\dist\BLRP2Excel> BLRP2Excel.exe

Any message(s) produced should help determine the cause of the issue.

Anaksunaman

Posted 2017-09-02T22:15:53.420

Reputation: 9 278

1This was actually enough to solve the issue for me! For some reason, though I installed xlsxwriter in my virtual env via Pycharm, the .exe couldn't locate it. I had to pip install it via a cmd prompt in the directory containing the script. – Johnny Apple – 2017-09-03T04:38:28.150

Glad you got it solved. =) – Anaksunaman – 2017-09-03T04:42:12.170