Cannot run my .exe python program using cx_freeze - python

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 !

Related

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

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

ImportError: No module named 'tkinter' executing .exe of pyInstaller [duplicate]

I want to do an executable, but ervery time I run the .exe it writes ImportError: No module named 'tkinter', and all I read on Stackowerflow do not help me !
My python program is simple (ODE solver) and requests only :
from math import*
from pylab import*
import numpy as np
import matplotlib
import numpy as np
import matplotlib.pyplot as plt
I paste a copy of my prog.py into the C:\Python\Scripts folder where pyInstaller is. I compute the command line pyinstaller -F eulersolver.py, this creates a prog.exe in the dist folder. When I run this code I have
ImportError: No module named 'tkinter'
Failed to execute script prog
But my program do not use this module... do you have any proposition or help for me ?
OS : Windows64
Python : 3.5 for Win64
Note : I already unistall/install python 3 times today (after reading documentation on this webside and abroad).
Note 2 : I use Python only for scientific issues. I am no computer scientist, so be kind to me when explaining computer stuff :S
FINALLY WORKED FOR pyinstaller -F --hidden-import=tkinter --hidden-import=tkinter.filedialog prog.py Thanks a lot !!!
You should use hidden import
pyinstaller eulersolver.py --hidden-import=tkinter -y
The problem is that pyinstaller won't see second level imports. So if you import module A, pyinstaller sees this. But any additional module that is imported in A will not be seen.
There is no need to change anything in your python scripts. You can directly add the missing imports to the spec file (prog.spec in your case).
Just change the following line:
hiddenimports=[],
to
hiddenimports=["tkinter"],
After that run pyinstaller prog.spec to create the prog.exe.

ImportError: No module named 'tkinter' after pyInstaller

I want to do an executable, but ervery time I run the .exe it writes ImportError: No module named 'tkinter', and all I read on Stackowerflow do not help me !
My python program is simple (ODE solver) and requests only :
from math import*
from pylab import*
import numpy as np
import matplotlib
import numpy as np
import matplotlib.pyplot as plt
I paste a copy of my prog.py into the C:\Python\Scripts folder where pyInstaller is. I compute the command line pyinstaller -F eulersolver.py, this creates a prog.exe in the dist folder. When I run this code I have
ImportError: No module named 'tkinter'
Failed to execute script prog
But my program do not use this module... do you have any proposition or help for me ?
OS : Windows64
Python : 3.5 for Win64
Note : I already unistall/install python 3 times today (after reading documentation on this webside and abroad).
Note 2 : I use Python only for scientific issues. I am no computer scientist, so be kind to me when explaining computer stuff :S
FINALLY WORKED FOR pyinstaller -F --hidden-import=tkinter --hidden-import=tkinter.filedialog prog.py Thanks a lot !!!
You should use hidden import
pyinstaller eulersolver.py --hidden-import=tkinter -y
The problem is that pyinstaller won't see second level imports. So if you import module A, pyinstaller sees this. But any additional module that is imported in A will not be seen.
There is no need to change anything in your python scripts. You can directly add the missing imports to the spec file (prog.spec in your case).
Just change the following line:
hiddenimports=[],
to
hiddenimports=["tkinter"],
After that run pyinstaller prog.spec to create the prog.exe.

cv loading for executable

I had imported cv2 library in my code and made an executable by using py2exe through GUI2EXE software.
Py2exe has created cv2.pyc file which is run every time the application is started and creates an error of 'Import Error: DLL load failed.Cannot find the module specified' at line mod = imp.load_dynamic(name,path). It has also made other files like numpy.core_sort which give the same error when run.
My question is that py2exe is only running the cv2.pyc file while running the application. Why is it doing so? It should have just imported the cv2 library.
The code in the cv2.pyc file is given below
def __load():
import imp, os, sys
try:
dirname = os.path.dirname(__loader__.archive)
except NameError:
dirname = sys.prefix
path = os.path.join(dirname, 'cv2.pyd')
#print "py2exe extension module", __name__, "->", path
mod = imp.load_dynamic(__name__, path)
## mod.frozen = 1
__load()
del __load
My code calls libraries in this manner :-
import wx
import wx.lib.buttons
import numpy as np
import os
import cv2.cv as cv #Import functions from OpenCV
from numpy import *
from PIL import Image #python imaging library
Looking at cv2.cpp it has #include "numpy/ndarrayobject.h"
so it looks like it loads numpy, which is not surprising.
As py2exe does not see the c++ source code, it will not detect this. So I think "the module specified" that can't be found is numpy.
Adding the following line to your setup.py should fix your problem:
import numpy

Categories

Resources