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.
Related
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?
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>')
Is it possible to repack/rebuild a PyInstaller exe file after extracting the files from it using PyInstaller Extractor? I also decomplied most of the files with Easy Python Decomplier. I modified one .py file and I want the new exe file to contain this modified file. How can I repack the application?
You may leave all not modified files as *.pyc.
Once you have full modules structure ready, just find the original entrypoint and pack the bundle again, it should work.
I have an .exe file where file compiled by py2exe in my .exe folder I have some .dll files, one .exe file and library.zip file and inside this zip I have to many .pyccompiled files.
I have decompiled this files from library.zip using Easy Python Decompiler and that program created me new file where I can see and change my code.
I have opened this file where I needed and I changed my code using python editor and finaly I saved as new script code with the some name and extension .pyc
with purpose to replace first .pyc.
zip again library folder and I tried to run .exe prgram but after the changes the program doesn't execute.
What have I done wrong in my task? Do I need to re-compile again in some way?
pyc and py file are NOT the same. While they represent the same code, they are totally different :
the py file represents the code you are typing, can be interpreted by the python interpreter, is not native, and is portable
the pyc file is a compiled version of the py file, that is not portable, not intended to be modified by an human, but faster
You cannot swap them and expect it to work. You will need to compile it to pyc before. You will find more information here : How can I manually generate a .pyc file from a .py 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.)