Problem with correctly running .exe file from python file - python

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')

Related

.exe python script created with Pyinstaller doesnt create text files

I have a simple script that reads in data from an excel file from within the same directory, does some analysis, and then creates 4 text files holding this analysis. The script works perfectly when run from the command line, but doesn't work when running from an exe created with Pyinstaller
The command I run to create the exe:
pyinstaller --onefile main.py
I have done nothing fancy in regards to file placement, the script expects the file it needs to be in the same directory, and I expect the text files to show up in the same directory
In the command line window that shows up, it does show the correct results because I have also printed them in the script.
I have used pandas and itertools within the script if that helps
EDIT:
It works without the --onefile option, but it would be best if it was just one file

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")

Mac no longer recognizes .py files?

I usually code on Atom, and recently, my Mac has just started to stop recognizing .py files as python files. It always recognizes those files now as TextEdit files, so that I can't even run the file without copy pasting the code into another file that my computer recognizes as a python file to run the code. Thanks for any help in advance.

Python script executable with py2exe or pyinstaller

My program contains 3 files (2x .py and .json). I would like to make single exe file. I tried py2exe with basic setup settings:
from distutils.core import setup
import py2exe
setup(console = ['my_main_file.py'])
It doesn't work. When I run exe file from dist directory terminal window blinks for a second. I tried also pyinstller but result is similar. How can I make it?
I solved it! I launched my .exe file from terminal and received an error "there is no file myfile.json" or something like that. I simply copied this file to disc directory and program works.

Using an external .dat file with a python script

I'm trying to use a python script to read statistics off of a file: savegame.dat
http://pastebin.com/DmsHfPhU is the script
The script came with instructions: "Use: python %script% %savegame.dat%"
I have python, I don't know where to put the savegame.dat file.
For some reason python launcher isn't working so I have to do it manually through the Terminal using the "python" command. I tried putting it in the same folder and it didn't work. I'd like to know what I need to change in the raw paste so it recognizes the savegame.dat. I tried dragging the script into the Terminal.app after opening the python command. With the script saved in the same place as .dat file.
Put it in the same directory as you are running the script in.
Save the paste in the link to a file. Call it foo.py. Put foo.py and the .dat file in the same directory.
Open the terminal.app. cd to the directory that both files are in, then type python foo.py savegame.dat
It doesn't matter where you put the file so long as you specify the full path to it on the command line.

Categories