transform python tkinter GUI to EXE file - python

I have been working on developing a GUI application using tkinter which is 100% working properly when running it from pycharm... and now I can't convert my script into an EXE file.
I have tried pyinstaller, cxfreeze and py2exe but everyone of them has a problem. pyinstaller show me 'Fatal error'... and cxfreeze seems to have a problem with MATPLOTLIB
Here are the libraries I am using:
import numpy as np
import tkinter
from random import randint
from tkinter import *
import tkinter as tk
from math import sqrt
from matplotlib.backends.backend_tkagg import (
FigureCanvasTkAgg, NavigationToolbar2Tk)
from matplotlib.backend_bases import key_press_handler
from matplotlib.figure import Figure
import matplotlib.pyplot as plt
from math import sqrt
from scipy import stats
from scipy.stats import beta
I don't want to post my code due to confidientality issues...
Does anybody has another idea ot do this ?
EDIT:
I reinstalled python as admin and reinstalled pyintaller
enter image description here
and when I tried to convert the script here is the command error it shows:
'pyinstaller' is not recongnized as an internal command or external ...
also I need to mention that the exe file of pyintaller in not founded in the directory of installation of python in C:programfiles/python37

Related

After I convert my script to executable file, it gives this error : MatplotlibDeprecationWarning

I have an error which's complete form is
MatplotlibDeprecationWarning: The MATPLOTLIBDATA environment variable was deprecated in Matplotlib 3.1 and will be removed in 3.3
I converted my script into executable file. After conversion, it never opened. When I execute script with IDEs(VS Code, Linux shell, and Spyder), it works. Somehow it does not open after I converted it to exe. I wrote some lines to avoid from this error, but simply it did not work. For example;
Python/matplotlib : getting rid of matplotlib.mpl warning
I used pyinstaller and auto-py-to-exe to convert my script into exe.
This is the beginning of my code:
from PyQt5.QtWidgets import *
from PyQt5.QtCore import Qt, QDate, pyqtSlot
from PyQt5.QtGui import QIcon
from datetime import datetime
import calendar
import sys
import numpy as np
import pandas as pd
from scipy.signal import find_peaks
import os
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas, NavigationToolbar2QT as NavigationToolbar
from matplotlib.figure import Figure
import matplotlib.dates as mdates
matplotlib.use('Qt5Agg')
myFmt = mdates.DateFormatter('%d')
It is very long to put all the code here. Thank you very much for your interest.
Arda, I've found out after trial and error that pyinstaller has a conflict with the latest version of matplotlib. In order to produce an executable of your script with pyinstaller you should downgrade matplotlib to 3.2.2 version. I have also found some problems with the latest (1.19.4) version of numpy which went away when I downgraded numpy to 1.19.3.
You can check my repository
https://github.com/matiasleoni/COVID19_plotter
where I created a simple script to plot COVID19 global data using matplotlib package. After many failed attempts I was also able to create an executable version of it as I described above (see also the README.md of that repository).

importError tkinter when importing matplotlib

I am unable to import matplotlib on this deep learning AMI from aws marketplace
import matplotlib.pyplot as plt
And I get this error
ImportError: No module named 'tkinter'
What I've tried (and the errors returned):
pip install tkinter
> No matching distribution found for TKinter
sudo yum install tkinter
> No package tkinter available.
> Error: Nothing to do
I personnally had this kind of troubles with tkinter, before to realize it requires a 't' in python3 and a 'T' in python2. so when I need compatibility my codes contain:
import sys
if sys.version_info[0]>2:
# for Python 3
import tkinter as tk
else:
# for Python 2
import Tkinter as tk
I hope this help
First find location of matplotlibrc file
import matplotlib
matplotlib.matplotlib_fname()
u'/usr/local/lib64/python2.7/site-packages/matplotlib/mpl-data/matplotlibrc'
Then go to this file and change the current configuration of backend to
backend : agg
This does not solve the problem of import Tkinter, but it does allow the import of pyplot
This worked for me:
import matplotlib
matplotlib.use('Agg')
import matplotlib.pylab as plt
Had the same problem after updating to new matplotlib 2.x on python 3.5.x

Cannot run my .exe python program using cx_freeze

I wrote a program where I imported those lib :
from math import*
from pylab import*
import numpy as np
import matplotlib
import matplotlib.backends.backend_tkagg
import numpy as np
import matplotlib.pyplot as plt
and I wanted to make an executable out of it (the .py already runs using pylab) so in the Windows terminal (in the Python's script folder) I did the command cxfreeze solver.py : this creates a solver.exe in Dist folder.
When I tried to run this executable, there is :
File "C:\Users\*****\AppData\Local\Programs\Python\Python35-32\lib\tkinter\__init__.py", line 35, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ImportError: DLL load failed: Le module spécifié est introuvable.
In english : the specified module is not found
I read several help on the site and on internet but it nerver fixed it, and after few days of searching I begin to give up. Please help !

how to build python application that contains a graph

When I run this script in a python shell it works perfectly but when I build the code and run the ".exe" file the application won't start.
from tkinter import *
import matplotlib,sys
matplotlib.use('TkAgg')
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
import matplotlib.pyplot as plt
master=Tk()
master.title("graphe")
master.geometry("700x650+100+100")
f=Figure((5,5),dpi=100)
a=f.add_subplot(111)
a.plot([1,2,3,4,5,6],[2,5,6,8,9,10])
data=FigureCanvasTkAgg(f,master=master)
data.show()
data.get_tk_widget().pack()
setup.py:
from cx_Freeze import setup,Executable
import sys
base=None
if(sys.platform=='win32'):
base="Win32GUI"
setup(name='application',
options={"build_exe":{"packages": ["tkinter","matplotlib","numpy","PIL","math"]}}‌​,
version="1.1",
executables=[Executable("graphe.py",base=base)]
)

Py2exe errors when building executable [duplicate]

This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
Outputed py2exe exe won't run only when signed: ImportError
I asked a similar question previously (Creating executable with Py2exe and matplotlib errors) that dealt with matplotlib errors. However, I have gotten past this stage. Now when I try to build my executable, none of my packages/code seem to import. For example, my code imports the following:
import os
import csv
import wx
import time
import math
from matplotlib.backends.backend_wx import FigureCanvasWx as FigureCanvas
from matplotlib.backends.backend_wx import NavigationToolbar2Wx
from matplotlib.pyplot import figure,show
from mpl_toolkits.basemap import Basemap
from matplotlib.figure import Figure
import matplotlib.pyplot as plt
from numpy.random import rand
from datetime import datetime
import wx.calendar as cal
import numpy as npy
from pylab import *
import numpy as np
import matplotlib
import adodbapi
import sqlparse
import pylab
import annote_new
import cPickle as pickle
I get a log error when I run my executable that it "No Module Named os". I get an error for every module I have in my code (if i change the order in which things are imported). Why aren't any of my modules importing? My Py2exe code looks like:
import os
from distutils.core import setup
import py2exe
from distutils.filelist import findall
import matplotlib
import glob
from matplotlib.backends.backend_wx import FigureCanvasWx as FigureCanvas
from matplotlib.backends.backend_wx import NavigationToolbar2Wx
from matplotlib.pyplot import figure,show
from mpl_toolkits.basemap import Basemap
from matplotlib.figure import Figure
import matplotlib.pyplot as plt
from numpy.random import rand
from datetime import datetime
import wx.calendar as cal
import numpy as npy
from pylab import *
import numpy as np
import matplotlib
import adodbapi
import sqlparse
import pylab
import annote_new
import cPickle as pickle
import wx
setup(
windows=[{'script': r'Scout_Tool.py'}],
data_files = [(r'mpl-data', glob.glob(r'C:\Python27\Lib\site-packages\matplotlib\mpl-data\*.*')),
(r'mpl-data', [r'C:\Python27\Lib\site-packages\matplotlib\mpl-data\matplotlibrc']),
(r'mpl-data\images',glob.glob(r'C:\Python27\Lib\site-packages\matplotlib\mpl- data\images\*.*')),
(r'mpl-data\fonts',glob.glob(r'C:\Python27\Lib\site-packages\matplotlib\mpl- data\fonts\*.*'))],
#matplotlib.get_py2exe_datafiles(),
options={
'py2exe':{
'includes': [
'matplotlib',
'matplotlib.backends.backend_wx',
'matplotlib.pyplot',
'mpl_toolkits.basemap',
'matplotlib.figure',
'numpy.random',
'wx.calendar',
'mpl_toolkits',
'numpy',
'datetime',
'wx',
'pylab',
'adodbapi',
'sqlparse',
'annote_new',
'cPickle',
'pylab'
],
'dll_excludes': ['MSVCP90.dll'],
}
},
)
Any thoughts on why my modules aren't importing after I run the py2exe? BTW, I get no errors when running the py2exe code -- only when i try to run the produced executable. Thanks!
EDIT
Okay, here is what i have done. I have taken out some of the modules that I weren't using and removed the duplicates. I also fixey my setup.py file to look like:
from distutils.core import setup
import py2exe
import matplotlib
import glob
setup(
windows=[{'script': r'Scout_Tool.py'}],
data_files = matplotlib.get_py2exe_datafiles(),
options={
'py2exe':{
'includes': [
'matplotlib',
'matplotlib.backends.backend_wx',
'matplotlib.pyplot',
'mpl_toolkits.basemap',
'matplotlib.figure',
'wx.calendar',
'mpl_toolkits',
'datetime',
'wx',
'adodbapi',
'sqlparse',
'annote_new',
'cPickle',
'pylab'
],
}
},
)
After this, I cleared out my entire 'dist' folder to be sure anything wasn't kept from before. Then I ran the following in CMD Prompt: C:\Python27\python setup.py py2exe. This ran with no errors.
Then when i go to run Scout_Tool.exe, I first get a MatPlotLib data error. I am not sure why i am getting this, but to fix it, I do the following: I unzip "library.zip", then add the "data" folder from Mpl-toolkits - basemap - data, then re-zip the library folder.
Then, when I try running Scout_Tool.exe, it comes up with the error that "No module named os" exists. This is true if I put any module first in my Scout_Tool.py code.
Hopefully this helps with where i am at? Thanks!
I compiled your program (the imports) and it runs OK for me.
the py2exe missed module report is not relevant if you are not using those modules (I got the same list as that you show).
Remember that the executable will run while you execute it within the dist module py2exe creates (and not from a copy in your desktop, for example. For that you need to make a direct access link).
Not going to take credit for this but do either of these help your problem?
http://www.python-forum.org/pythonforum/viewtopic.php?f=3&t=6659
Outputed py2exe exe won't run only when signed: ImportError
This question is also a continuation of
py2exe doesn't import the os module?

Categories

Resources