How to prevent Pyinstaller from extracting files in Temp - python

I am using an executable file generated with Pyinstaller from my Python script.
Every time I open it, it creates a folder named (for example) _MEI12345 in \AppData\Local\Temp.
How can I prevent the creation of that folder? Are there other (better) ways to create an executable file if I have to distribute it?

Related

Create a python executable shortcut - path issue

I created an executable with pyinstaller. The file is in the directory Build and I need to have several shortcuts of this .exe in many different directories. The problem is, my program uses an Excel table which will be accessed through a relative path. So when I use a shortcut of my .exe, the Excel table can't be found because the relative path works for the original .exe but not for the shortcut.
How can I access the Excel table?

How to avoid python running file in the directory where the code is located?

I'm writing a script that will download an executable from the internet, which will create more files. Now, if I download the file, it will be downloaded to the directory I told it, but when I open it using os.startfile(), it creates the files to the directory where the python script is located. How can I avoid that?
Either you can move the .py file to any other directory.
or
You can use os.chdir() to change the current working directory of the script during the runtime.
os.chdir('/path/to/directory')
Do a os.chdir() before trying to run the executable:
os.chdir('<the target folder where you want the files to be created>')
...
os.startfile('<path to where the executable was downloaded>')

Generate an executable file in python

I have proceeded to generate an executable file using pyinstaller, once it has finished the corresponding files are generated, then:
In my windows console I apply this command: pyinstaller --onefile program_with_excel.py
I use this command to compile everything into a single.exe file, so that I can use it on another pc.
Once this is done, I open my executable located in the 'dist' folder and when doing so I have detected several problems:
My executable file 'program_with_excel.exe' is too heavy for what I am trying to do, a few simple calculations. (317,948 KB)
When I open it, the following error appears and then my application closes:
I suspect it is because to run my program I use an excel sheet using 'pandas' where I place data and they are calculated with my program. How could this be resolved?
What would be the solution for this problem and be able to work with my executable?
I also attach a rar with my program and my excel sheet: RAR_EXAMPLE
Best regards.
The exe needs to have access to all its dependencies, just like the python script. If you moved it then it may not have that access. It appears from the error that this is the problem. A common way these exe files are transported is by putting it and each dependency in a zipped folder and using NSIS.

how to change bundled data file pyinstaller on execute

I'm making onefile executables with pyinstaller on windows 10. I'm including data files (pickle files) by editing the .spec file...
How can I store changes made to these files during run time? My understanding is that the data files are copied to a temp directory during execution. I can read from the files using the path I get from sys._MEIPASS but the changes I write are lost after restarting the program.
Is there a way to write to pickle files stored inside the exe?
Do not mention the pickle file to pyinstaller and put the pickle file in the same folder than the bundled onefile. For me this works even if you have two files in the folder instead of one.

When I try to write to a file using python script in a batch file and then run it. It doesn't write to the file

I have tried writing some content to a file by running a python code in a batch file.I have used the following as the batch command.
python C:\Python27\filtercsv.py
When I tried running the program in IDLE or in the command prompt, it was writing to the file. But, when I tried the same using the batch file, it wasn't writing.
I have included python in the PATH environment variable. So, I guess I don't need to specify the .exe file's location.
Can anyone tell me how to solve this issue?
Do you write the file to an absolute path?
If not you might want to either change the current directory in the batch file before running the script:
pushd C:\Python27
python filtercsv.py
popd
or include a path in the file name you're writing to.
This is because of if you write to a file just by name it will show up in the current working directory, which is not necessarily where the script is located.
(However, you should probably not save your scripts in your Python installation directory, nor write files there because you don't usually have write access there.)

Categories