how to build python application that contains a graph - python

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)]
)

Related

Importing library in python (Pycharm)

These are the libraries within the script asked for import
## Import libraries
import numpy
import dill
import pandas
import peakutils
import os
import scipy
from scipy.signal import butter, lfilter, freqz
import smooth
from peakutils.plot import plot
from matplotlib import pyplot
I did several however, not for butter,lfilter, freqz, os,
what I have to do?
I imported several libraries but not all.

Freezing Python program - Imports are always skipped

I've been trying for a few days to freeze a Python program. I've tried py2app, PyInstaller and cx_freeze. Of all 3, cx_freeze seemed to be the most effective.
py2app and PyInstaller seems to skip all my imports whichever settings I'm using. The modules needed are always found in "Modules not found (unconditional imports)" with py2app. With PyInstaller, everything seems to run fine, but the program fails to launch due to the fact that no modules is imported, even when specified as hidden import.
For cx_freeze, some imports seems to be done, as it is at least trying to import PyQt5.
But cx_freeze failed at this step with this error:
File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/shutil.py", line 120, in copyfile
with open(src, 'rb') as fsrc:
FileNotFoundError: [Errno 2] No such file or directory: '/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/QtCore.framework/Versions/5/QtCore'
For information:
Python version: 3.7.2, installed with Anaconda3.
List of imports:
import sys
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
from PyQt5 import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
OS used: MacOS 10.11.16
Targeted OS for freezing: MacOS (various versions)
At this point, I don't really know what to do to freeze my programe. If anyone has an idea, that would be awesome.

PyCharm creating executable file, ImportError: Failed to import any qt binding for QT interface

I have followed the solution in the post title ImportError: Failed to import any qt binding, Python - Tensorflow to solve my executable file error
File "matplotlib/backends/qt_compat.py", line 168, in <module>
ImportError: Failed to import any qt binding
[10262] Failed to execute script AI_DES_CONDA
But the solution of reinstalling matplotlib with updated pip didn't work in my case
I have used pyinstaller to create the executable file using the following command:
pyinstaller --onefile AI_DES_CONDA.py
Python used in creating the file and interface is 3.7.5
The libraries used are:
import time
import time
import os
import csv
import pandas as pd
import matplotlib.backends.backend_qt5agg
#matplotlib.use('Qt5Agg')
import matplotlib.pyplot as plt
#import matplotlib.pyplot as plt
from PyQt5.QtGui import QPixmap
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5 import QtWidgets, QtGui
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from sklearn import model_selection
from sklearn.model_selection import train_test_split
from sklearn.model_selection import cross_val_score
from sklearn.linear_model import LogisticRegression
from sklearn.tree import DecisionTreeClassifier
from sklearn.neighbors import KNeighborsClassifier
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
from sklearn.naive_bayes import GaussianNB
from sklearn.svm import SVC
from sklearn.preprocessing import LabelEncoder
from sklearn import tree
from sklearn.metrics import accuracy_score
import pickle
from PIL import Image
import numpy as np
import seaborn as sns
from mpl_toolkits.mplot3d import Axes3D
import seaborn as sb
import warnings
from sklearn.preprocessing import StandardScaler
from sklearn.preprocessing import StandardScaler
from PyQt5.QtCore import Qt
Please see image for more details:
Note: I am using pycharm to create the executable file.
Any advice?
Thanks
I got an error like that. re-install is a way but there might be more than one package at the path with same name.
i.e. if there is numpy-stl and stl in the same path we might get that error.
by the way you should pip3 to install pip3 install mathplotlib

transform python tkinter GUI to EXE file

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

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