root = tk.Tk()
img = PhotoImage(file=f'C://Users/{os.getlogin()}/downloads/monitor.png')
root.tk.call('wm', 'iconphoto', root._w, img)
root.title(' Screen Recorder')
root.geometry('+260+70')
root.resizable(width=False,height=False)
st_icon = PhotoImage(file=f'C://Users/{os.getlogin()}/downloads/rec.png')
sp_icon = PhotoImage(file=f'C://Users/{os.getlogin()}/downloads/stop.png')
cam_icon = PhotoImage(file=f'C://Users/{os.getlogin()}/downloads/webcam0.png')
com_icon = PhotoImage(file=f'C://Users/{os.getlogin()}/downloads/webcam1.png')
shot = PhotoImage(file=f'C://Users/{os.getlogin()}/downloads/screenshot.png')
This is my code and I have 6 icons that I want to include in that exe file plus I have multiple libraries that I want to include in this.
My main motive is that anybody should able to run this file on any computer without installing all those libraries if that is possible.
You can use pyinstaller to create an exe. But you need to include all the files in the same folder as the exe.
pip install pyinstaller
pyinstaller --onefile --windowed --icon=icon.ico main.py
Related
import extruct
def main():
input("Hello")
if __name__ == '__main__':
main()
This is the code that I converted into an exe file with pyinstaller. If I open this file now, the exe crashes directly. At the bottom is the message:
FileNotFoundError: [WinError 3] The system cannot find the specified path: 'C:\Users\test\AppData\Local\Temp\_MEI801802\mf2py\backcompat-rules'"
It is definitely because I am importing "extruct". But I need this library for the correct code. Does anyone know how I can fix this error?
I got it to work... these are the steps I took. Im using windows. On another operating system the only changes that need to be made are the virtual environment path to the bakcompat-rules directory.
create a new empty directory and copy and paste your code into main.py file
py -m venv venv
venv/Scripts/activate
py -m pip install --upgrade pip pyinstaller extruct
pyinstaller -F main.py
This will create a main.spec file. open it and at the top paste the following
import os
data = []
parent = "./venv/Lib/site-packages/mf2py/backcompat-rules/"
for item in os.listdir(parent):
path = os.path.join(parent, item)
target = parent
data.append((path, "mf2py/backcompat-rules"))
in same file in Analysis signature change datas=[], to datas=data,
pyinstaller main.spec
dist/main.exe
And it should run fine.
I am trying to create an executable with pyinstaller for a python script with tix from tkinter. The following script also demonstrates the error:
from tkinter import *
from tkinter import tix
root = tix.Tk()
root.mainloop()
I have Python 3.9 installed and the script runs fine and works as intended but after using pyinstaller to create an executable, the .exe file fails to run because it can't find the package Tix.
One of the solutions mentioned here which is to copy the C:\Python39\tcl\tix8.4.3 folder to the dist directory for the executable worked for me. The executable runs as intended after copying the folder, but I would like to package the script into one exe without needing to supply the tix8.4.3 folder.
Is there anyway to package the tix folder when building the executable with pyinstaller?
It works for me using below command to generate the executable:
pyinstaller -F --add-data C:\Python38\tcl\tix8.4.3;tcl\tix8.4.3 main.py
Note that I use PyInstaller 4.7 and Python 3.8.12 under Windows 7.
you have error in code:
from tkinter import *
from tkinter import tix
root = tix.Tk() # Here it was TK
root.mainloop()
I have 3 python scripts and many images in folders and tmx files which I want to make it as a single .exe . I wasnt able to find how to convert multiple python scripts and folders to single exe. I was only able to find cxfreeze and similar things for a single python script. Please help.
Thanks in advance.
You can add external files to your pyinstaller exe by using add-data. An example I'm using for one of my pygame games:
pyinstaller --onedir --clean --name "MyGame" --icon="images/icon.ico" --add-data "images/*.png:images" --add-data "sounds/*.mp3:sounds" --add-data "sounds/*.wav:sounds" --add-data "fonts/*.ttf:fonts" main.py
Create a setup.py file in cxfreeze. You have to pass multiple pyhton files as list in cxfreeze executables. Refere this thread -
Python cx_Freeze for two or more python files (modules)
For separate files like images, you have to include those files explicitly. Below is an example which worked for me on one of the project -
from cx_Freeze import setup, Executable
build_exe_options = {'packages': ['os', 'tkinter', 'matplotlib.backends.backend_svg', 'subprocess'],
'namespace_packages': ['mpl_toolkits'],
'include_files':['input3.json', 'SF.xlsx', 'SF logo.ico', 'Operative Temperature.pkl',
'Rect_icon.png', 'Soltissim logo.png', 'SF full logo.jpg', 'IES logo.jpg']}
base = None
if sys.platform == 'win32':
base = 'Win32GUI'
setup ( name = 'Soltissim',
version = '2',
description = 'SF GUI',
options = {'build_exe': build_exe_options},
executables = [Executable('Soltissim.py', base=base, icon='SF logo.ico'),
Executable('SF_English.py', base=base, icon='SF logo.ico'),
Executable('SF_French.py', base=base, icon='SF logo.ico')])
Furhter, if you want to create a build from setup which can be then used in program like inno, use following command in terminal - python setup.py build
If you want to create a simple windows installer directly from setup, use - python setup.py bdist_msi
I have working Python project which use pytesseract library.
I tested it in PyCharm. Python ver. 3.7.
Now I'm trying to compile this project to exe using PyInstaller.
When I run exe I got error:
File "getTextFromScreen.py", line 5, in ModuleNotFoundError:
No module named 'pytesseract' [9188] Failed to execute script main
My import in code looks like:
import pytesseract
pytesseract.pytesseract.tesseract_cmd = r'Tesseract-OCR\tesseract'
I provide whole 'Tesseract-OCR' folder in python project folder and compiled project folder.
I don't know what do I do wrong.
I want to ask you for help
Are you using windows? You must include the .exe extension in your path. Instead just r'Tesseract-OCR\tesseract', use r'Tesseract-OCR\tesseract.exe'. I have a project using PyTesseract too, provide a whole tesseract folder in python project and working well after compiled using PyInstaller.
If you want to create an .exe and run it from any other pc where the Tesseract is not, you must use the auto-py-to-exe tool, in the additional files option attach the folder where all the Tesseract files were installed, then put this in your code
import sys
if getattr(sys, 'frozen', False):
_path = os.path.join(sys._MEIPASS, './tresseract/tesseract.exe')
print(_path)
pytesseract.pytesseract.tesseract_cmd =_path
# the .exe will look here
else:
pytesseract.pytesseract.tesseract_cmd = r"C:\tresseract\\tesseract.exe"
#ruta donde se encuentre su tresseract
and compile, good luck !!
I'm using cx_freeze to pack my Python script as a standalone executable.
The exe is running fine on the machine it was packed (with python 3.5 and all the relevant packages).
But when I copied the folder cx_freeze created to another machine the I got this error:
My cx_freeze script:
import sys
import numpy
import os.path
from cx_Freeze import setup, Executable
os.environ['TCL_LIBRARY'] = r'C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\tcl\tk8.6'
setup(
name = "DocSum",
version = "1.0",
options = {"build_exe": {"packages":["idna","asyncio", "encodings","numpy", "jinja2.ext"]}},
description = "DocSumRESTfulServer",
executables = [Executable("DocSumRESTfulServer.py", base = None)]
)
Any idea what could be the reason? I thought that the exe should be a standalone (run on machines without python). Am I wrong?
It seems that not all dependencies were compiled successfully.
If you want to have a standalone executable, I recommend pyinstaller.
Just pip install it then:
pyinstaller.exe --onefile yourFile.py
The --onefile flag is used to package everything into a single executable. Your executable file would be found on the dist folder.
You could also try this site.
I had the same problem. At the end I discovered that I need to copy also my python37.dll and the lib directory.
If the exe, dll and the directory are on the same directory, it works.
I would like to have a single exe too.