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.
Related
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 this code which i need to create it as a python exe file, where in user has to click the workflow done.
My Sample Project
import os
import pandas as pd
import sys
import csv
path = os.getcwd()
v1 = pd.read_csv(r"path\V1.tsv", delimiter = '\t')
v1.to_csv(r"path\v2.csv", index=False)
I used Pyinstaller to create a .exe file but it didnt help me achieve what I want. Can some one suggest me?
Depending on what disappointed you about PyInstaller, (speed? size? too many files in directory?), you may either want to try:
PyInstaller's --onefile flag, which will compile everything into one .exe file but will take forever to run
cx_Freeze. This can generate .exe files like PyInstaller, though performance won't be much better. What I find most useful is to compile the files into an installer by calling py setup.py bdist_msi (Windows) or py setup.py bdist_dmg (Linux). People can use the installer to add the .exe to their machines. Installer-created .exe files will run very quickly.
Have your tried using the --onefile flag to specify that you only want 1 exe file to be created for that script.
For example use the cmd: pyinstaller --onefile file_name.py
If this does not help can you specify the issue that is occurring.
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")
I created a python script which opens some tabs and some programs and in a directory creates a folder. Now the problem is when using pyinstaller i converted this .py file into .exe file it was succesfully converted but when i ran this .exe file in virtual machine windows 7 it gives an error
The program can't start because api-ms-wncrt-runtime-I1-1-0.dll is missing.
Is there a way to include all such modules inside the .py file so that the program runs somehow
UPDATED
i used pyinstaller -w -F .py. Now i copied the exe file
only into the shared folder cuz i only want the exe file .
Following are the modules i imported in my python code
import tkinter
import input1
import input2
import random
import webbrowser as wb
from tkinter import *
import subprocess
import os So is there a way to include any library or module which will solve this issue
Did you use the -F option when using pyinstaller?
When you do:
pyinstaller -F python_file.py
It grabs all of the modules you've used to make the package (provided you have them in your envrionment I think) and makes it into one file. If it makes a separate folder for the libraries, you have to copy the folder around with the exe file or it won't work.
If this ms-wncrt-runtime is not a python module then afaik you can't add this to your python package and will need to install it on your machine separately. Hope that helps.
I have generated python exe using py2exe but getting cmd window when I run my program.
I have changed my files from .py to .pyw and again generated .exe file but I am still getting cmd window.
How to generate exe that doesnot show cmd.
Note I am using Tkinter in my code.
Thanks
There is a simple way of doing it in Python:
Change your directory with cd into this one where your desired .py file is.
Pip install Pyinstaller.
when you succeeded typing following line: pyinstaller.exe --onefile -w NAME.py and hit enter. NAME is the name of your specific py file.
Now have a look in your chosen directory where are new files created. Look for the exe file which should be in the Dist folder.
Just copy paste it where ever you want and delete the rest.
Still
questions?
Just watch this video.