.exe python script created with Pyinstaller doesnt create text files - python

I have a simple script that reads in data from an excel file from within the same directory, does some analysis, and then creates 4 text files holding this analysis. The script works perfectly when run from the command line, but doesn't work when running from an exe created with Pyinstaller
The command I run to create the exe:
pyinstaller --onefile main.py
I have done nothing fancy in regards to file placement, the script expects the file it needs to be in the same directory, and I expect the text files to show up in the same directory
In the command line window that shows up, it does show the correct results because I have also printed them in the script.
I have used pandas and itertools within the script if that helps
EDIT:
It works without the --onefile option, but it would be best if it was just one file

Related

Python Pytest files to convert single executable file and executed via batch file

I have 10 pytest files and the demand is to convert these to a single executable file, The project contains properties file in which data is present.I need the data for pytest as in the console I was running via python -m pytest but in pyinstaller it is asking for a single .py file to be converted. I tried but came into no solution. Please help me its important. Even though I convert to a single executable the exe file never runs.
In Java I used to create a jar file and it can be processed via .bat file and it reads data from properties file and it works
If in python something like that we can achieve will be welcomed

Windows- Pyinstaller unless folder contains file appear error “failed to execute script"

I have a problem to over come the following error, when i am running my program packed using pyinstallet into standalone executable.
In the program i am using an icon file to set iconbitmap. The file is located in the same folder as the python script.
master = Tk()
master.wm_title("P&P Util ")
master.iconbitmap('logo.ico')
In addition i am adding and icon to the executable in the packing process.
pyinstaller -F -w -i "C:\temp\Util\logo.ico" main.py
Now after some testing i located that when i add file itself to the packed executable, the program is running without any issues. I understand that i need to change the way i am using the file but i don't know how.
Your advice will be very much appreciated.
It looks like it is crashing because you have not added the "logo.ico" file to the package, so when master.iconbitmap('logo.ico') looks for the icon, it is not there. With the command -i 'C:\temp\Util\logo.ico' you are telling pyinstaller to set that icon file as the windows icon, but this is not the same as including it in the package. To do that try including this in your pyinstaller command:
--add-data "C:\temp\Util\logo.ico;."
The "." after the semi-colon tells pyinstaller where to put the file. In this case it will put it into the same folder as the .exe file.

Getting cmd window with python exe from py2exe

I have generated python exe using py2exe but getting cmd window when I run my program.
I have changed my files from .py to .pyw and again generated .exe file but I am still getting cmd window.
How to generate exe that doesnot show cmd.
Note I am using Tkinter in my code.
Thanks
There is a simple way of doing it in Python:
Change your directory with cd into this one where your desired .py file is.
Pip install Pyinstaller.
when you succeeded typing following line: pyinstaller.exe --onefile -w NAME.py and hit enter. NAME is the name of your specific py file.
Now have a look in your chosen directory where are new files created. Look for the exe file which should be in the Dist folder.
Just copy paste it where ever you want and delete the rest.
Still
questions?
Just watch this video.

How to make a Python script run without it opening the console window?

I want to double click on my Python script (which uses a Tkinter GUI) and I just want it to open the Tkinter window, not the console window.
To do this, I changed the extension from .py to .pyw and this seems to work fine on Windows but when I double click my .pyw file on a Linux machine, it doesn't work. It simply froze and I had to restart my system.
Please suggest a platform-independent solution that would help me to run the Python script without opening the terminal/command prompt.
it's been a while since i tried on linux, but i believe it should be fairly simple, firstly you need to put a shebang at the top of the script so your shell knows which executable to use:
#!/usr/bin/python
or if you want a specific version you can expand this to:
#!/usr/bin/python3.2
using whichever version you want (only works for first 2 digits)
then you need to mark it as executable:
chmod 711 myfile.py
for more info on this see this page
then when you double click it, on the rpi (last i used linux) it asks if you want to execute it, or execute it in the terminal.
if you choose to execute it without the terminal, you should only see the tkinter GUI
You can use pyinstaller to create the executables for the different platforms you want.
For example,
The syntax of the pyinstaller command is:
pyinstaller [options] script [script ...] | specfile
In the most simple case, set the current directory to the location of your program myscript.py and execute:
pyinstaller myscript.py
PyInstaller analyzes myscript.py and:
Writes myscript.spec in the same folder as the script.
Creates a folder build in the same folder as the script if it does not exist.
Writes some log files and working files in the build folder.
Creates a folder dist in the same folder as the script if it does not exist.
Writes the myscript executable folder in the dist folder.
In the dist folder you find the bundled app you distribute to your users.
Normally you name one script on the command line. If you name more, all are analyzed and included in the output. However, the first script named supplies the name for the spec file and for the executable folder or file. Its code is the first to execute at run-time.
For certain uses you may edit the contents of myscript.spec (described under Using Spec Files). After you do this, you name the spec file to PyInstaller instead of the script:
pyinstaller myscript.spec
You may give a path to the script or spec file, for example
pyinstaller options... ~/myproject/source/myscript.py
or, on Windows,
pyinstaller "C:\Documents and Settings\project\myscript.spec"
pyinstaller

Using an external .dat file with a python script

I'm trying to use a python script to read statistics off of a file: savegame.dat
http://pastebin.com/DmsHfPhU is the script
The script came with instructions: "Use: python %script% %savegame.dat%"
I have python, I don't know where to put the savegame.dat file.
For some reason python launcher isn't working so I have to do it manually through the Terminal using the "python" command. I tried putting it in the same folder and it didn't work. I'd like to know what I need to change in the raw paste so it recognizes the savegame.dat. I tried dragging the script into the Terminal.app after opening the python command. With the script saved in the same place as .dat file.
Put it in the same directory as you are running the script in.
Save the paste in the link to a file. Call it foo.py. Put foo.py and the .dat file in the same directory.
Open the terminal.app. cd to the directory that both files are in, then type python foo.py savegame.dat
It doesn't matter where you put the file so long as you specify the full path to it on the command line.

Categories