python exe errors when running by an external program - python

I have python exe file which has been made using cx_Freeze. Basically The script uses the text file "XYZ.txt" to generate a word cloud. When I run the python exe file everything is fine and the code runs well, but I am planning to run it from an external program (a game which generates the text file) and when I'm trying to run it from that game, python exe runs but gives me the FileNotFoundError: [Error 2] No such file or directory: 'XYZ.txt'. But the 'XYZ.txt' actually is in the same folder and at the same time. Besides, I tried to run the text file from that game and it opened but the python exe cannot find it.
I have also tried to run my game as administrator and then running the python exe and then I got: "dll load failed the specified module could not be found" instead of the previous error.
I would be thankful if anyone could help me with that.

please give the absolute path for 'XYZ.txt' in your python code. I guess that might solve the problem.

Related

Is there a way to make an executable file that runs a python file in which a different python file is executed?

I have a big python project which I'm currently developing, and I want to make a .exe file that launches the main.py file. I have a file called ultimate_launcher.py which has the following code:
exec(open("main.py").read())
That is a solution I found somewhere on Stack Overflow. it runs fine as a .py file, but when I use pyinstaller to convert it to a .exe, it has a "Fatal" error,
Failed to execute script ultimate_launcher
I don't want the rest of my project to be put into the .exe as I am still in the process of development.
So my question is how do I make a .exe that ONLY references the file main.py so when it gets updated, i don't have to remake the .exe file.
I believe there is a method to achieve this detailed in this thread:
Python - create an EXE that runs code as written, not as it was when compiled
EDIT:
This works
import subprocess
f = open("c:\\temp\\temp.py", "w")
f.write(open("main.py").read())
f.close()
subprocess.call("\"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\Python37_64\\Scripts\\pyinstaller.exe\" --distpath \"c:\\temp\" c:\\temp\\temp.py " )
subprocess.call("C:\\temp\\temp\\temp.exe")

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 can I get an .exe file to recognize a file in the same folder, when called from a Python script?

I'm on day two of a desperate attempt to run a Windows executable from a Python script. This .exe file is opaque to me; in other words, I don't know how to open it up to look at the source code. But importantly, this executable needs to be located in the same directory as a csv file full of parameters in order to work.
When I call the file directly in the command line:
C:\Users\pb\nw_river> Run_Model.exe
the executable works exactly as expected.
However, when I try to call the same file from some python code:
import subprocess
subprocess.Popen(["C:\Users\pb\nw_river\Run_Model.exe"], shell=True)
I receive error messages that indicate that the executable can't "see" the required csv file.
I don't have any of these problems when I run the script on my macbook (MacOS Catalina 10.15.3), but I really need to get this to run on my work computer, which has a Windows 10 Pro OS.
I'm a total noob to Windows. Has anyone ever experienced this issue, and do you have any advice? Thanks in advance!

How to resolve "memory cannot be written" for py2exe?

When I run an EXE file which was created by py2exe, everything is running fine, but when I close the window, it gives the following error:
memory cannot be written
What is going wrong? Whatever I do,the cue is still received. But when I run the .py file directly, everything is running ok.

How to run an EXE file using Standalone python script

i'm trying to run an exe file (say foo.exe) using python script exported to exe (say boo.exe) using py2exe, it always give the below error as can't find the specified file, but i'm pretty sure the foo.exe is exist and on same directory with boo.exe, the code works fine before exporting the script into exe !
WindowsError: [Error 2] The system cannot find the file specified: 'C:\\Users\\test\\Desktop\\foo.exe'
the code is
os.startfile("foo.exe")
is it somekind of bug or limitation like this one

Categories