pandas v0.17.1 not working with py2exe - python

I Have a problem with python pandas v0.17.1. I upgraded from v0.16.2.
System:
Win10 x64, Python 3.4 64Bit, using PyCharm Community Edition for coding.
(numpy 1.9.3+mkl)
I'm using py2exe to create a stand-alone of a statistics program, using pandas to hold the data, matplotlib for plotting and pyqt4 for everything related to gui.
Since i upgraded pandas, the created .exe from py2exe doesn't work anymore. After doubleclick or start from commandline nothing happens. No Errors, no Errorlog file or similar, no 'window flashing' open and close again. just nothing.
I uninstalled pandas and reinstalled (fresh install) it via pip. Same problem.
I just downgraded pandas to v0.16.2 again. Everything works fine now (with v0.16.2). No other changes made.
For the sake of testing i created a simplest program as possible, only an empy pyqt mainwindow and whats needed to start the programm. works fine witout pandas. After 'import pandas' nothing happens anymore (with v0.17.1).
Somebody knows whats going on? Do i have to tweak my setup.py for the new pandas version? Because i dont get any error, i cannot check whats wrong.
main.py:
# coding=utf-8
import sys
from PyQt4 import QtCore, QtGui
import matplotlib
#import pandas
class app(QtGui.QMainWindow):
def __init__(self, *args):
QtGui.QMainWindow.__init__(self, *args)
if __name__ == "__main__":
programm = QtGui.QApplication(sys.argv)
window = app()
window.show()
eventloop = programm.exec_()
sys.exit()
setup.py:
# coding=utf-8
from distutils.core import setup
import py2exe
path_to_source = r'path to dir' # replace with your working directory
setup(
options = {"py2exe": {
'includes': ['sip'],
'excludes': [],
'optimize': 2,
'compressed' : False,
'packages': ['encodings']
#'skip_archive': True
}},
zipfile = None,
windows = [{"script": path_to_source + r"/main.py"}]
)
Just uncomment the import statement of pandas and nothing works anymore with v0.17.1.
The 'dist' directory gets created with a the same files as before.
I tried to 'include' pandas in setup.py but no effect. Dont know what to do to solve this. Are some dll's needed in the setup.py now?
Sorry for my bad english.
ps: In PyCharm, everything works fine, it's only the .exe that does not work.
ps2: Tested the same with my Win7 installation, same behavior.

I solved my problem. It was my AVAST Anti-Virus. It's 'deepscreen' feature started the programm in the background as a sandbox and analysed the .exe but never informed me about it running in the back (no info baloon etc.).
By chance, i had it deactivated while looking into Calvin's Answer.
It works on both, my PC and Laptop now, without any changes. Just deactivated AVAST 'deepscreen' feature while using the .exe created py py2exe.

I've been having the same issue as well. What I found was that a packaged called 'nbformat' caused the py2exe script to fail. I added this package into my excludes list and the script ran successfully.

Related

creating standalone exe using pyinstaller with mayavi import

I have a program that helps visualize some data in 3D by plotting a surface and a cloud of points to see how they relate to the surface. For the visualization I am using mayavi since it was easy to set up and does a better job than matplotlib in 3D. The program works great when I run it in my python environment and makes beautiful visualizations. However, I need to distribute this to a few people who don't have Python and would prefer not to have to install python and all the add-ins on each computer, so I have been using pyinstaller to create standalone .exe files that they can run after I develop a program.
For reference, this is all done on Windows 10, Python 3.6, pyqt 4.11.4, pyface 6.0.0, traits 4.6.0, pyinstaller 3.3.1, mayavi 4.5.0+vtk81. Just about every module I use was installed using pip.
The problem is that I can't seem to get a working exe if I use/import the mayavi module. I have been reading so much github documentation on different hook files and hidden-imports and each time I fix one error another pops up. It all started with scipy but I believe I have those worked out. So I have a few questions that could help me solve the problem:
1) Has anyone successfully created a standalone exe using pyinstaller with a mayavi import (specifically from mayavi import mlab)? What is your secret?!?
This seems similar but I haven't been able to figure it out yet... SO_link
I have used the following links (scipy,h5py,pandas,traits/qt4,ETS_TOOLKIT) to add hidden imports or fix other issues but I am stuck now after setting my ETS_TOOLKIT=qt4. Before setting it, I would get a pyface/traits error RuntimeError: No traitsui.toolkits plugin found for toolkit null, but now it says the same thing for qt4 instead of null. I have qt4 installed so I don't understand that... It is in the import_toolkit function in pyface/base_toolkit.py.
2) Is there a better route to go in terms of 3D visualization / exe creation? I need a 3D program that can accurately render if the points are in front of or behind the surface and be able to rotate/zoom/pan interactively, plus it needs to be intuitive. Mayavi had very simple commands similar to matplotlib but others seem very complicated working around how the UI interacts with everything.
3) How do I interpret all of these error codes I get? They are usually pretty cryptic saying a certain line threw an exception nested in 10 other function calls and it seems very difficult to back out where exactly things went wrong, especially when nothing pops up on Google that seems to be related.
EDIT
While I am still very confused, I have been able to change where the error occurs. Following the traceback, I commented out a line setting the marker color in traitsui/editors/code_editor.py (line 49), at which point the exception then started the next time the Color method was called... but I still get the same RuntimeError. So that doesn't tell me much other than I am still looking for what hidden import I need to include for this thing to work.
Also note that I get the exact same error with both PyInstaller and cx_Freeze, in case that helps...
Edit 2
I have now tried it using anaconda for python 2.7, SAME EXACT ISSUE..... I'm starting to believe the universe doesn't want this to happen. Is there somewhere else I should bring this issue up?? I have posted on the traitsui GitHub but that wasn't very helpful. This seems to be bigger than pyinstaller/cx_freeze since it happens in both....
I dealt with the same problem and finally switched to cx_freeze, which now works fine on linux and windows. The problems you are dealing with arise from statements like in the SE answer, you found, i.e. dynamic import statements, where what is imported is only determined at runtime:
be = 'pyface.ui.%s.' % tk
__import__(be + 'init')
I couldn't fix that in pyinstaller, while in cx_freeze it works, when you explicitely add the required packages in the build file. Here is the package list I used:
"packages": ["pyface.ui.qt4", "tvtk.vtk_module", "tvtk.pyface.ui.wx", "matplotlib.backends.backend_qt4",'pkg_resources._vendor','pkg_resources.extern','pygments.lexers',
'tvtk.pyface.ui.qt4','pyface.qt','pyface.qt.QtGui','pyface.qt.QtCore','numpy','matplotlib','mayavi']
Here is a full build script that works with python3.6, cx_freeze 5.0.2, mayavi 4.5.0+vtk71, traits 4.6.0, pyface 5.1.0 and traitsui 5.1.0.
import os
from cx_Freeze import setup, Executable
import cx_Freeze.hooks
def hack(finder, module):
return
cx_Freeze.hooks.load_matplotlib = hack
import scipy
import matplotlib
scipy_path = os.path.dirname(scipy.__file__) #use this if you are also using scipy in your application
build_exe_options = {"packages": ["pyface.ui.qt4", "tvtk.vtk_module", "tvtk.pyface.ui.wx", "matplotlib.backends.backend_qt4",'pygments.lexers',
'tvtk.pyface.ui.qt4','pyface.qt','pyface.qt.QtGui','pyface.qt.QtCore','numpy','matplotlib','mayavi'],
"include_files": [(str(scipy_path), "scipy"), #for scipy
(matplotlib.get_data_path(), "mpl-data"),],
"includes":['PyQt4.QtCore','PyQt4.QtGui','mayavi','PyQt4'],
'excludes':'Tkinter',
"namespace_packages": ['mayavi']
}
executables = [
Executable('main.py', targetName="main.exe",base = 'Win32GUI',)
]
setup(name='main',
version='1.0',
description='',
options = {"build_exe": build_exe_options},
executables=executables,
)
I import pyface in the following way:
os.environ['ETS_TOOLKIT'] = 'qt4'
import imp
try:
imp.find_module('PySide') # test if PySide if available
except ImportError:
os.environ['QT_API'] = 'pyqt' # signal to pyface that PyQt4 should be used
from pyface.qt import QtGui, QtCore
before importing mayavi

Creating exe file with cx_Freeze, PyQt4, matplotlib and multiple .py files does not work

I'm currently struggeling to build my python project with cx_Freeze into an exe file and I'm not sure what I did wrong as I used the examples (PyQt4 and matplotlib) of Anthony Tuininga (https://github.com/GreatFruitOmsk/cx_freeze/tree/finder_zip_pkgs/cx_Freeze/samples) to do that.
I have three .py files, one main file, one ui file and one functions file.
And of course the setup.py file.
I import only these packages in my files:
from PyQt4 import QtCore, QtGui
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
I use Python 3.4.3 64-bit (from mini conda)
matplotlib 1.5.1, cx_Freeze 4.3.4 64-bit and Windows 10 64-bit
My setup.py file looks like this:
from cx_Freeze import setup, Executable
buildOptions = dict(packages=["atexit"],
#I also tried this one: #packages=["PyQt4.QtGui","PyQt4.QtCore","matplotlib"],
#and instead of matplotlib, I also tried this one #"matplotlib.backends.backend_qt4agg"
excludes=["Tkinter"],
include_files=["Factory.ico","Main_Functions.py","Main_Ui.py"])
base = 'Win32GUI'
executables = [
Executable('Main.py', base=base,icon="Factory.ico",compress = True)
]
setup(name="Simulator",
version="0.0.1",
description="NA",
author="NA",
author_email="NA",
options=dict(build_exe=buildOptions),
executables=executables)
The build process runs through without any errors (at least I don't find any) but once I want to start the application, I get the following error message which I don't understand as the directory C:\Python does not exists.
I have also seen that others have the same problem but their solution did not worked for me or I did it wrong.
Could you please help me with this as I don't know what else to do and I'm getting a bit frustrated :(
Thank you very much in advance :)

import rich_ipython_widget in a py2exe excutable

I am building an executable for my python software in which I have an interactive python terminal widget. It works perfectly if I run it in python, but it fails to run if I double click the .exe I constructed with py2exe. I isolated the problem and it drops down to a simple line of code:
from IPython.qt.console.rich_ipython_widget import RichIPythonWidget
if I put this unique line in a test.py file and I run it, there is no error. now I build the .exe with py2exe using the following setup.py file:
from distutils.core import setup
from py2exe.build_exe import py2exe
setup(name = "Test",
console=[{"script":"testShell.py"}], options={})
then the resulting error message, when running the executable, is:
ImportError:
Could not load requested Qt binding. Please ensure that
PyQt4 >= 4.7 or PySide >= 1.0.3 is available,
and only one is imported per session.
Currently-imported Qt library: 'pyqt'
PyQt4 installed: False
PySide >= 1.0.3 installed: False
Tried to load: ['pyqt']
Since the app is working in python, this means that the problem is not that pyqt is not installed, but not found.
I am facing a wall here, let me know if you have a clue?
I have fixed this exact same issue by modifying the file "qt_loader.py" (in C:\Python27\Lib\site-packages\IPython\external).
What you have to do it just force the "has_binding" function to return "True".
The problems lies in the "imp.find_module" which does not work with py2exe!
Here, this is really a "false positive", (i.e. a test that fails while there is no actual problem). Skipping the test solves the issue.

No module named when using PyInstaller

I try to compile a Python project under Windows 7 using PyInstaller. The project works fine, there are no issues, however when I try to compile it the result doesn't work. Though I get no warnings during compilation there are many in the warnmain.txt file in the build directory: warnmain.txt
I don't really understand those warnings, for example "no module named numpy.pi" since numpy.pi is no module but a number. I never tried to import numpy.pi. I did import numpy and matplotlib explicitly. In addition I'm using PyQt4. I thought the error might be related to those libraries.
However I was able to compile a simple script which uses numpy succesfully:
import sys
from PyQt4 import QtGui, QtCore
import numpy as np
class MainWindow(QtGui.QMainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.pb = QtGui.QPushButton(str(np.pi), self)
app = QtGui.QApplication(sys.argv)
main = MainWindow()
main.show()
sys.exit(app.exec_())
Successfully here means that the created executable file actually showed the desired output. However there is also a warnmain.txt file created which contains exactly the same 'warnings' as the one before. So I guess the fact that compiling my actual project does not give any success is not (or at least not only) related to those warnings. But what else could be the error then? The only output during compilation are 'INFO's and none of the is a negative statement.
I did not specify an additional hook directory but the hooks where down using the default directory as far as I could read from the compile output, e.g. hook-matplotlib was executed. I could not see any hook for numpy neither could I for my small example script but this one worked. I used the following imports in my files (not all in the same but in different ones):
import numpy as np
import matplotlib.pyplot as ppl
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg as NavigationToolbar
from PyQt4 import QtGui, QtCore
import json
import sys
import numpy # added this one later
import matplotlib # added this one later
Since PyInstaller does not give any errors/warnings I could not figure out if the problem is related to the libraries or if there is something else to be considered.
Had a similar problem with no module named FileDialog. Discovered that with version 3.2, I could use
pyinstaller --hidden-import FileDialog ...
instead of modifying my main script.
See Listing Hidden Imports documentation
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.
Just change the following line:
hiddenimports=[],
to
hiddenimports=["Tkinter", "FileDialog"],
If you are getting ModuleNotFoundError: No module named ... errors and you:
call PyInstaller from a directory other than your main script's directory
use relative imports in your script
then your executable can have trouble finding the relative imports.
This can be fixed by:
calling PyInstaller from the same directory as your main script
OR removing any __init__.py files (empty __init__.py files are not required in Python 3.3+)
OR using PyInstaller's paths flag to specify a path to search for imports. E.g. if you are calling PyInstaller from a parent folder to your main script, and your script lives in subfolder, then call PyInstaller as such:
pyinstaller --paths=subfolder subfolder/script.py.
The problem were some runtime dependencies of matplotlib. So the compiling was fine while running the program threw some errors. Because the terminal closed itself immediately I didn't realize that. After redirecting stdout and stderr to a file I could see that I missed the libraries Tkinter and FileDialog. Adding two imports at the top of the main solved this problem.
I was facing the same problem and the following solution worked for me:
I first removed the virtual environment in which I was working.
Reinstalled all the modules using pip (note: this time I did not create any virtual environment).
Then I called the pyinstaller.
The .exe file created thereafter executed smoothly, without any module import error.
I had the same problem with pyinstaller 3.0 and weblib. Importing it in the main didn't help.
Upgrading to 3.1 and deleting all build files helped.
pip install --upgrade pyinstaller
If the matter is that you don't need Tkinter and friends because you are using PyQt4, then it might be best to avoid loading Tkinter etc altogether. Look into /etc/matplotlibrc and change the defaults to PyQt4, see the 'modified' lines below:
#### CONFIGURATION BEGINS HERE
# The default backend; one of GTK GTKAgg GTKCairo GTK3Agg GTK3Cairo
# CocoaAgg MacOSX Qt4Agg Qt5Agg TkAgg WX WXAgg Agg Cairo GDK PS PDF SVG
# Template.
# You can also deploy your own backend outside of matplotlib by
# referring to the module name (which must be in the PYTHONPATH) as
# 'module://my_backend'.
#modified
#backend : TkAgg
backend : Qt4Agg
# If you are using the Qt4Agg backend, you can choose here
# to use the PyQt4 bindings or the newer PySide bindings to
# the underlying Qt4 toolkit.
#modified
#backend.qt4 : PyQt4 # PyQt4 | PySide
backend.qt4 : PyQt4 # PyQt4 | PySide
May not be a good practice but installing pyinstaller in the original environment used in my project (instead of a separate venv) helped resolve ModuleNotFoundError
I had similar problem with PySimpleGUI.
The problem was, pyinstaller was installed in different directory.
SOLUTION (solved for me) : just install pyinstaller in the same directory in which the file is present (that to be converted to exe)
If these solutions don't work, simply deleting and reinstalling pyinstaller can fix this for you (as it did for me just now).
Putting this here for anyone else who might come across this post.
I had the same error. Mine said "ModuleNotFoundError: No module named 'numpy'". I fixed it by typing the following in the cmd:
pip install pyinstaller numpy

Using bundle_files = 1 with py2exe is not working

After some big frustration I did it! I converted my django app to an "exe" one to run as a single standalone app on windows (using cherrypy as a WSGI server)
But When I try to to set py2exe's option "bundle_files" to "1" (i.e. bundle the python interpreter Python25.dll inside the generated exe) the generated exe crashes with a message talking about kernel32.dll
But when I use "bundle_file" = "2", the generated exe is runing like a charm, but must -of course- have Python25.dll as a separate file beside it.
Anyone experienced a similar behavior, can you please tell me what I'm missing?
Thank you! :)
this post talks all about using py2exe to get a single exe file.
py2exe - generate single executable file
If you post some code i'll take a look, and your error message will help to.
Maybe you can try pyinstaller instead.
I did have this problem before and didn't find a solution ever, but pyinstaller meets my need too and works perfectly.
I also faced similar problem. But mine is with PyGTK. Simple program has no problem with it. Although there is no straight solution, there is an explanation provided here.
It says:
This is based on the Inno sample code in the py2exe distribution. It has worked successfully for a rather complicated PyGTK/Twisted app requiring extra data at runtime (GTK runtime data, GtkBuilder files, images, text data) that just wouldn't work with bundle_files.
Here's The solution:
from distutils.core import setup
import py2exe, sys, os
sys.argv.append('py2exe')
setup(
options = {'py2exe': {'bundle_files': 3}},
windows = [{'script': "Your_App_Name.py"}],
zipfile = None,
)

Categories