A
A
Alexis_D2019-12-31 08:36:13
WordPress
Alexis_D, 2019-12-31 08:36:13

How to fix error when opening compiled python file?

Good day, when you run this code, in the development environment,

from tkinter import *
import tkinter as tk

root = Tk()

image = tk.PhotoImage(file="icon.png")
Button(root, image=image, command=lambda: print('click')).pack()

root.wm_state('zoomed')
root.mainloop()

Everything starts up fine, everything works, but when I compile this file and run it, it gives the error "Failed to execute script" what's the problem? Thanks in advance for your reply

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
riot26, 2016-03-19
@riot26

get_user_by()

M
MechanicZelenyy, 2019-12-31
@MechanicZelenyy

My version of libastral is a bit old, but I'll try: add a line like #!/usr/bin/python (for linux) to the beginning of the file.

T
Ternick, 2019-12-31
@Ternick

Well and than you so to speak 'compile'?
In general, tkinter is hard to compile :)
I advise you to try pyinstaller :) - in theory it's even better than cx_freeze because the 'build' is smaller !
Well, if all the same cx_freeze then I advise you to use this script to 'compile' :

import os
from cx_Freeze import setup, Executable

os.environ['TCL_LIBRARY'] = "C:\\Users\\Ternick\\AppData\\Local\\Programs\\Python\\Python36\\tcl\\tcl8.6"
os.environ['TK_LIBRARY'] = "C:\\Users\\Ternick\\AppData\\Local\\Programs\\Python\\Python36\\tcl\\tk8.6"

buildOptions = dict(
    packages = [],
    excludes = [],
    include_files=['C:\\Users\\Ternick\\AppData\\Local\\Programs\\Python\\Python36\\DLLs\\tcl86t.dll', 'C:\\Users\\Ternick\\AppData\\Local\\Programs\\Python\\Python36\\DLLs\\tk86t.dll']
)

import sys
base = 'Win32GUI' if sys.platform=='win32' else None

executables = [
    Executable('1.py', base=base)
]

setup(name='editor',
      version = '1.0',
      description = '',
      options = dict(build_exe = buildOptions),
      executables = executables)

Just enter your details! On the way there, almost everything was the same!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question