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
Related
Accidentally deleted the python code, all i have is a single unix executable file generate by pyinstaller.
Is there a way to reverse this and to extract my code ?
I want to run .exe file from python file, but there is problem with reading from txt file.
Exe doesn't throw any errors, but it looks like it doesn't even open any .txt.
Additionally, .exe works well, when I enter the folder and run it manually.
How I run .exe in python:
subprocess.check_call(['D:\Projects\PythonProjects\PrivateGithub\MinMax\EXE\Run.exe'])
Should I do something 'special' to be able to read from files?
Try this code to run the exe:
import os
os.startfile('D:\Projects\PythonProjects\PrivateGithub\MinMax\EXE\Run.exe')
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.
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.
so my ultimate goal is to use python to read a specific application's windows event log when triggered by a file update.
Here is my problem, python I believe does not have access to the event logs stored in C:\Windows\System32\winevt\Logs. Whenever I try to read the files I get the following error:
WindowsError: [Error 2] The system cannot find the file specified
I tried every form of escaping, string split/join and using quotes on the file path and I always get the same error. I even cheaply used the os.system('dir "C:\Windows\System32..."') command in the python command prompt to list directories higher in the path for the log to verify access and I receive similar errors up to the C:\Windows\System32 directory, that one will list just fine.
Example:
C:\Windows\System32\winevt\Logs - File not found
C:\Windows\System32\winevt - File not found
C:\Windows\System32 - Lists files
I know these directories exist. So from here I figured I could use a bash script to copy the event log into a temp folder for python to read. I wrote a real simple bash script containing:
xcopy /Y "C:\Windows\System32\winevt\Logs\XXXXXXX" c:\Temp
(XXXXXXX) being the name of the log I want to copy for the python script.
The bash script runs fine on its own but when called by my python script it fails, refuses to copy the file because it can't find it. I have even tried using py2exe to create an exe to then run in administrator mode. This failed too. With similar errors of the file not found. I'm not sure I understand the permissions python uses to call the script and why the bash script cannot copy the file even when it can do it in a normal command prompt.
Any suggestions or flaws you can point out in my logic would be great. I am very stuck.
You are using a 32bits python on a 64bit install of windows.
In most cases, whenever a 32-bit application attempts to access %windir%\System32, the access is redirected to %windir%\SysWOW64
You can use os.listdir("c:\windows\sysnative\winevt\logs") as a workaround to read from the real system32 dir from a 32bit python interpretter runing on a 64bit windows...
Sources:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa384187(v=vs.85).aspx
http://support.microsoft.com/kb/942589