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?
Related
I have a problem with the plotly package. To be precise, I'm using auto-py-to-exe in order to have a file .exe which, if the users asks for it, plots a table using the plotly package. My code goes like this:
import pandas as pd
import plotly.graph_objects as go
import numpy
df= pd.read_excel (r'C:\Users\user\Desktop\Program\Data_Studio_Def.xls')
visualize_table= input('visualize table of patologies? (yes/no)')
if visualize_table== yes
fig = go.Figure(...)
fig.show()
Now, when I run the .exe made by auto-py-to-exe on the CMD (OS: Windows 10), I get some errors regarding modules like
Module plotly.validators.table not found
Once I add all such modules via hidden-import, I get the error:
FileNotFoundError No such file or directory : C\Users\user\output...
so it is searching for the plot in a folder rather than actually print it and I don't know how resolve this. Should I provide further informations?
P.S. I found out that the main problem is caused by the plotly package itself: I tried to build the exe via cx_Freeze rather than pyinstaller and the result was:
Module plotly.validators.table has no Attribute CellsValidators
Doing some searching I found out I'm not the only one with the same problem, the "HasNoAttribute", but uninstalling the package to then reinstall it again didn't do anything unfortunately.
I'm working on my first gui exe. I'm using the anaconda packages with spyder and the code works fine there. Math, pyplot, numpy, tkinter, and PIL are imported, and the app is fully functional with the exception of pyplot which will not show up when activated from a button widget.
If instead I create a simple exe with the code:
import numpy
import matplotlib.pyplot as plt
x=numpy.linspace(1,100)
fig,ax=plt.subplots()
lineData,=ax.plot(x,3*x)
I get one error during the initial build:
ModuleNotFoundError: No module named 'Crypto.Math'
and many warnings, but note that the analysis warning file contains no errors either.
Running the created exe, I get failure and cmd exits. Running from cmd initially instead and turning on debug and verbose imports yields tons of warnings, but no errors.
I've tried including hidden imports like 'matplotlib.pyplot','matplotlib','Crypto', and importing Crypto, to no avail. Crypto is not being called anywhere and the reference plot in the build folder says only pyinstaller imports it. I'm at a loss here for what the problem could be.
Packages in anaconda folder
Ok, so it turned out to be a simple fix. lineData,=ax.plot(x,3*x) will plot/show the figure in spyder/Ipython, but not when called in the exe or python standalone, so I had to add plt.show().
From there I made a virtual environment with the latest packages and needed to
downgrade numpy to 1.16.2 per this thread, and now everything works.
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.
PyCharm says it can't find the reference to some of my packages, even if the project interpreter is correctly set, and the packages that I'm trying to use are already installed using pip, on PyCharm's built in Package Installer.
Screenshot: https://i.imgur.com/a2DY3K0.png
I have already tried:
Switching between several Python interpreters
Removing and reinstalling the packages
Restarting PyCharm & Windows
example code (see the screenshot above):
from bs4 import BeautifulSoup
from tkinter import Tk
print(BeautifulSoup)
print(Tk)
what the PyCharm tooltip says:
Cannot find reference 'BeautifulSoup' in 'imported module bs4'
Cannot find reference 'Tk' in 'imported module tkinter'
what the actual output is, when running the program:
<class 'bs4.BeautifulSoup'>
<class 'tkinter.Tk'>
I put a .py using ATOM IDE, called the .py in cmd command and got the following error saying that the module can't be found: Trackback (most recent call last): File "widgets.py", line 5, in from bokeh.layouts import layout ImportError: No module named layouts.
The same syntax ran fine in Jupyter...without warning for layouts module name.
Anyone has a clue? Is it possible my Python version and the bokeh version are compatible?
The code in widgets.py is the following:
from bokeh.io import output_file, show
#create text box on webpage, and text
from bokeh.models.widgets import TextInput, Button, Paragraph
#arrange the widgets
from bokeh.layouts import layout
After a bit investigation, I found that it's because I was using the cmd command line rather than the Anaconda Prompt environment. Now I am in the correct environment, the .py code generates a bokeh server as it is supposed to.