Not understanding the path of files in Python exe output - pyinstaller

my Python project works in editor. I get .exe output from Python (.py) program. The .exe file could not understand the path of the files.
import os
a = os.getcwd() + "\\Logs\\" # Find the log directory
# Read the text in the Paths.txt file inside the logs directory
b = open (a + "Paths.txt", "r").read()
When the code is executed in the editor, the text inside the file is read and the file path is understood. But when executing the .exe file, the program can not detect the path of the log file.
Log file path at runtime (in editor or .py): currect and understood
'C:\\Users\\mohammad\\Desktop\\projects\\Logs\\Paths.txt'
Log file path at runtime (in .exe file): not currect
'C:\\Users\\mohammad\\Desktop\\projects\\dist\\Logs\\Paths.txt'
I tried some methods such as short route but it did not work.
Also, due to my problems, I output Python file as follows:
pyinstaller.exe --onefile --add-binary "C:\\Users\\mohammad\\Desktop\\projects\\pythoncom310.dll\\;." Start.py
And i'm using version 3.9 of Python and the VScode editor. Thanks for your time

Related

Executable file not found

I have a python code that is taking some info from a website by selenium and then write them into a json file, after I created an '.exe' file by pyinstaller and run it I don't know where this json file is saved.
Where could be saved, should be in the initial directory?

Pyinstaller for arm 32bit compilation

I am using Ubuntu as a host system,.compiled for 32bit manually chosen the bootloader, with respect to that create bundle Python file. And copy into my arm target board.
The error which I am facing is not able to execute the binary file
In my arm board.
I cannot able to bundle .my .csv files with executable using --add-data. While running the executable, it searches my CSV file in the current folder, it shows error as file not found error.
how to add multiple files (CSV and INI) files with my executable.
How to fix this issue.
Regards
Rajalakshmi
For adding data files you need to First, provide your data files with --add-data flag. Then because your data would be extracted on a temp directory, you need to set its address for your app. In below example, I'm addressing all CSV files from resource_path function which would return the relative path for each file.
I assume that you put all your files in data directory beside your app.
app.py:
import os
import sys
def resource_path(relative_path):
if hasattr(sys, '_MEIPASS'):
return os.path.join(sys._MEIPASS, relative_path)
return os.path.join(os.path.abspath("."), relative_path)
if __name__ == "__main__":
csv_files = ["data/a.csv", "data/b.csv", "data/c.csv"]
print("Reading CSV files from data directory")
for csv_file in csv_files:
with open(resource_path(csv_file), "r") as f:
print(csv_files, ":", f.read())
print("Done!")
You can then generate your executable with:
pyinstaller app.py -F --add-data "./data/*;data/"

Use PyInstaller to package data files in the EXE

How do I package files into an EXE file that is generated via PyInstaller --onedir?
I see, that I can add the file with
a.zipped_data+=["version.json", "version.json", "DATA]
PYZ(a.pure, a.zipped_data)
pyi-archive_viewer shows the file in PYZ-00.pyz
But
pkg_util.find_loader("testmod").get_data("version.json")
does not find the file.
NB: I can't use --onefile mode, because it would need to unpack several 100 MB at each program start. And I want to tie several files (not only the version file) with the executable.
The name passed to get_data was wrong.
For an Windows executable c:\test\testpgm.exe the correct name would be c:\test\version.json
In Linux the executable might be /usr/local/bin/test/testpgm and the correct name would be /usr/local/test/version.json

How to generate standalone exe file from python 3.6 scripts

How to convert .py file into standalone exe file for python3.6, please explain with examples
Please explain it with some examples to make setup.py file, so that I can execute any text file called in python script and save the output in csv file by calling the csv file.

jar file not found iexpress

I am using iexpress to make my .jar files into .exe files
for this I add the jar file(myjarfile.jar) and in run command box I type : java -jar myjarfile.jar
but after creating the .exe the cmd that is flashing says cannot find the jar file myjarfile.jar
can any body help me find what I am doing wrong
To test this, I built a simple HelloWorld.jar file (using these instructions) and tested it like so:
java -jar HelloWorld.jar
Then I made an IExpress package with it. The Install program was exactly the command I used above. This worked exactly as it should.
Two possible causes of the error:
In the IExpress wizard, there's a checkbox Store files using Long File Name inside Package. You should definitely select this option; ignore the warning that appears, as it applies to Windows 95/98. In the .sed file, this is:
UseLongFileName=1
Check that the .exe actually contains myjarfile.jar. 7-Zip will open the .exe and show you the archive contents. (IExpress .exe files are just a CAB file with a wrapper.) If the file is missing, then you'll need to check your .sed file to see what went wrong.

Resources