I have a python (3.8.3) script which works perfectly. However, when I create an executable with the following command :
pyinstaller --onefile gui.py
I get the following error : **
cannot import name ttk from tkinter
The error appears at this line :
from tkinter import ttk
I can not remove the import as "ttk" is really needed in my program.
I tried to create it with cx_freeze but I get the same error.
Do you have any solution for this problem ? Thanks.
Try one of these ways to compile your script:
pyinstaller --onefile gui.py --hidden-import=tkinter.ttk
pyinstaller --onefile gui.py --hidden-import=tkinter
If you tackle another import problem it would be better to compile using .spec file where you can specify hidden imports
Related
I am trying to create a EXE file using auto-py-to-exe (pyinstaller). My script implements tkinter to create a GUI. However, when I run pyinstaller, this error message appears.
AttributeError: partially initialized module 'tkinter' has no attribute 'Tk' (most likely due to a circular import)
975818 ERROR: Tcl/Tk improperly installed on this system..
I have viewed solutions however none of them are working for me.
I found this page to be helpful:
PyInstaller exe returning error on a Tkinter script
However, I cannot find the file locations on my computer and do not think they exist.
binary='/System/Library/Frameworks/Tk.framework/Tk':'tk'
--add-binary='/System/Library/Frameworks/Tcl.framework/Tcl':'tcl' your_script.py
I did find a script called tcl_Tk.py and it is associated with hooks
I read that script and found this:
TODO Shouldn't these be fatal exceptions?
if not tcl_root:
logger.error('Tcl/Tk improperly installed on this system.')
return []
if not os.path.isdir(tcl_root):
logger.error('Tcl data directory "%s" not found.', tcl_root)
return []
if not os.path.isdir(tk_root):
logger.error('Tk data directory "%s" not found.', tk_root)
return []
I do not have tk_root or Tcl_root installed. And have been using tkinter from Anaconda Navigator (anaconda3) environment
Other background information:
I am using Spyder(3.8) as my IDE
Imports:
import tkinter as tk,
import pandas as pd,
from PIL import Image, ImageTk,
import matplotlib.pyplot as plt,
plt.style.use('ggplot')
Any solutions how I can get this to work?
I'm trying to build my application to .exe with PyInstaller, but it seems, that PyQt3D module doesn't imports PyQt3D module.
It is impossible to build application with Qt3D with PyInstaller, or I need some extra configuration for this? I tried to add PyQt3D module in hidden-imports, but still have an error:
Traceback (most recent call last):
File "***\main.py", line 1, in <module>
from PyQt5 import QtWidgets, Qt3DCore, Qt3DExtras, Qt3DRender, QtGui, QtCore
ModuleNotFoundError: No module named 'PyQt5.Qt3DInput'
[13512] Failed to execute script main
I passed --hidden-import PyQt5.Qt3DInput to PyInstaller.
But still, I've got this:
Qt3D.Renderer.Jobs: unsupported format encountered (stl)
When I'm running my application in PyCharm everething is OK.
Maybe anyone can help with this?
Find out that to start import models with setSource() I need to add PyQt5/Qt/plugins/geometryloaders to PyQt5. So full command to build onefile PyQt3D Application is:
pyinstaller %input_file% --onefile --hidden-import PyQt5.Qt3DInput --add-data "venv/Lib/site-packages/PyQt5/Qt/plugins/geometryloaders";"PyQt5/Qt/plugins/geometryloaders"
So i wrote a little programm in python with use of tkinter. The repo is found here: https://github.com/Odatas/MeisterTools
I now want to create an exe so people only need to use the exe when they want to use the program. But the exe i create with pyinstaller doesnt work and throws the error:
Import Error: cannot import name 'travel' from 'main'
The cmd i opend to creat the exe is directly out of anaconda envoirment.
I cd into the folder where all the scripts are and then run it like this:
pyinstaller --onefile patrickstools2.py
I even tried to make every import an hidden import:
pyinstaller --onefile --hidden-import=init --hidden-import=main --hidden-import=checker --hidden-import=contact --hidden-import=dangers --hidden-import=droptable --hidden-import=importexcel --hidden-import=odatasfunctions --hidden-import=randomenpc --hidden-import=scrolltest --hidden-import=sonstiges --hidden-import=travel patrickstools2.py
that doesnt help either. I added the path through Anaconda to the PYTHONPATH variable...so it should be know in any way shape or form.
The complet code is in Anaconda. The Error gets thrown in the import section of the main file:
# page classes import
import os
try:
import Tkinter as tk
except ImportError:
import tkinter as tk
try:
import ttk
py3 = False
except ImportError:
import tkinter.ttk as ttk
py3 = True
# page classes import
from . import travel
from . import contact
from . import dangers
from . import sonstiges
from . import randomenpc
I allready created an exe with pyinstaller from a previous version. But i made some changes to the structure of the programm. The run.py is only there because i work with spyder and as far as i know spyder needs it because else the import doesnt work correctly.
SOLUTION:
The main issue was occurring due to ImageTk , this can be skipped by loading image using tkinter instead of PIL.ImageTk by using this command and using this object as normal you would do with PIL.ImageTk.
my_image = PhotoImage(file ="Image location here")
MAIN ISSUE:
I'm trying to pack these files into a single executable file using pyinstaller, but after compilation, the executable file doesn't run, don't know where the error is, files in the given link, and installation log in pictures
Command Used:
pyinstaller --onefile ui.py
Where ui.py is my driver script
Files:
https://github.com/RoyalEagle73/NIT-JSR-Result-Leecher/tree/master/GUI%20%2B%20Source%20v2.0/Source
Build Log( Images ):
What I've already tried
tried Cx_Freeze as an alternative but no application seems to open the output file.
here is what I'm importing overall in the whole program
from tkinter import *
from PIL import ImageTk, Image
import fb
from tkinter.ttk import Progressbar
import webbrowser
from tkinter import messagebox
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import re
from bs4 import BeautifulSoup
import time
I was not able to access the github link in your question, I think it did not get pasted properly. So I am unable to access your source files.
Try one of these:
pyinstaller --onefile --noupx ui.py
or
pyinstaller --debug --onefile --noupx ui.py
The pyinstaller uses UPX. The documentation for pyinstaller states the following:
PyInstaller looks for UPX on the execution path or the path specified
with the --upx-dir option. If UPX exists, PyInstaller applies it to
the final executable, unless the --noupx option was given. UPX has
been used with PyInstaller output often, usually with no problems.
Hope this helps.
I know there's already a question like this but the answer didn't work for me.
When I append the py2exe argument in the program, and run it, I noticed it's missing a bunch of files. Also when I run the exe, it says
File "boot_common.py", line 46 in <module>
ImportError: No module named 'ctypes'
Can anyone help me on how to fix this? Here's my code:
from distutils.core import setup
import py2exe, sys
import tkinter as tk
from tkinter import filedialog
input('Press Enter to continue and select your Python file you want to convert when the dialog shows up...')
tk.Tk().withdraw()
file_path = tk.filedialog.askopenfilename()
sys.argv.append("py2exe")
setup(console=[file_path])
Also if it helps, I'm using a 32-bit Python interpreter.