I have a Python Qt GUI which is using these modules:
"Numpy, scipy, matplotlib-base, netcdf4, cartopy, xarray, pytest, gdal, cycler, dateutil, kiwisolver, pillow, pyparsing, tk, PyQt5, pycairo, tornado, proj4, geos"
Project has many components and plugins. It is working correctly through python but I want to convert it to 'one file exe' and easily run in other systems. I tried pyinstaller, when i run the exe file, it is running but no windows open. Do you have any suggestions for converting projects to exe correctly with modules or how can I add modules to following setup.py?
Edit: Tried cx-freeze, successfully creating the exe file but it closes as soon as it opens. I can run the file in terminal without any problem.
This is my setup.py:
def configuration(parent_package='', top_path=None):
from numpy.distutils.misc_util import Configuration
config = Configuration('rd1project', parent_package, top_path)
config.add_subpackage('core')
config.add_subpackage('components')
config.add_subpackage('plugins')
config.add_subpackage('scripts')
config.add_subpackage('components.corrections')
config.add_subpackage('icons')
config.add_data_dir('icons')
return config
if __name__ == '__main__':
from numpy.distutils.core import setup
setup(**configuration(top_path='').todict())
This is my main.py:
import sys
import os
path = os.path.dirname(sys.modules[__name__].__file__)
path = os.path.join(path, '..')
sys.path.insert(0, path)
import artview
try:
from version import profiling
except:
profiling = False
def main(argv):
if profiling:
import cProfile, pstats
pr = cProfile.Profile()
pr.enable()
script, DirIn, filename, field = artview.parser.parse(argv)
if script:
artview.scripts.scripts[script](DirIn, filename, field)
else:
artview.run(DirIn, filename, field)
if profiling:
pr.disable()
stream = open('profile.txt', 'w')
ps = pstats.Stats(pr, stream=stream).sort_stats('cumulative')
ps.print_stats('artview')
stream.close()
if __name__ == "__main__":
main(sys.argv)
I tried to pyinstaller, exe file is running but no windows opening after a while fatal error detected windows shows up "Failed to execute script main"
pyinstaller --onefile --noconsole main.py
Output:
1176 INFO: PyInstaller: 4.2
1176 INFO: Python: 3.8.5 (conda)
1177 INFO: Platform: Windows-10-10.0.18362-SP0
1178 INFO: wrote C:UsersPCpyinstallerartview\__main__.spec
1182 INFO: UPX is not available.
1197 INFO: Extending PYTHONPATH with paths
['C:\Users\PC\pyinstaller', 'C:\Users\PC\pyinstaller\artview']
1221 INFO: checking Analysis
1221 INFO: Building Analysis because Analysis-00.toc is non existent
1222 INFO: Initializing module dependency graph...
1227 INFO: Caching module graph hooks...
1234 WARNING: Several hooks defined for module 'win32ctypes.core'. Please take care they do not conflict.
1238 INFO: Analyzing base_library.zip ...
3545 INFO: Processing pre-find module path hook distutils from 'C:\Users\PC\anaconda3\lib\site-packages\PyInstaller\hooks\pre_find_module_path\hook-distutils.py'.
3546 INFO: distutils: retargeting to non-venv dir 'C:\Users\PC\anaconda3\lib'
6501 INFO: Caching module dependency graph...
6643 INFO: running Analysis Analysis-00.toc
6656 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
required by C:UsersPCanaconda3python.exe
6746 INFO: Analyzing C:UsersPCpyinstallerartview\__main__.py
10909 INFO: Processing pre-safe import module hook setuptools.extern.six.moves from 'C:\Users\PC\anaconda3\lib\site-packages\PyInstaller\hooks\pre_safe_import_module\hook-setuptools.extern.six.moves.py'.
11420 INFO: Processing pre-find module path hook site from 'C:\Users\PC\anaconda3\lib\site-packages\PyInstaller\hooks\pre_find_module_path\hook-site.py'.
11421 INFO: site: retargeting to fake-dir 'C:\Users\PC\anaconda3\lib\site-packages\PyInstaller\fake-modules'
14977 INFO: Processing pre-safe import module hook six.moves from 'C:\Users\PC\anaconda3\lib\site-packages\PyInstaller\hooks\pre_safe_import_module\hook-six.moves.py'.
20666 INFO: Processing pre-safe import module hook urllib3.packages.six.moves from 'C:\Users\PC\anaconda3\lib\site-packages\PyInstaller\hooks\pre_safe_import_module\hook-urllib3.packages.six.moves.py'.
C:UsersPCanaconda3libsite-packagespyartcoregrid.py:318: SyntaxWarning: "is not" with a literal. Did you mean "!="?
if meta is not 'data':
45679 INFO: Processing module hooks...
45680 INFO: Loading module hook 'hook-certifi.py' from 'C:\Users\PC\anaconda3\lib\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks'...
45685 INFO: Loading module hook 'hook-cryptography.py' from 'C:\Users\PC\anaconda3\lib\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks'...
45917 INFO: Loading module hook 'hook-IPython.py' from 'C:\Users\PC\anaconda3\lib\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks'...
46426 INFO: Excluding import of tkinter from module IPython.lib.clipboard
46432 INFO: Excluding import of PyQt5.QtWidgets from module IPython.external.qt_loaders
46433 INFO: Excluding import of PyQt5.QtCore from module IPython.external.qt_loaders
46433 INFO: Excluding import of PyQt5.QtSvg from module IPython.external.qt_loaders
46433 INFO: Excluding import of PyQt5.QtGui from module IPython.external.qt_loaders
46434 INFO: Excluding import of PyQt5 from module IPython.external.qt_loaders
46440 INFO: Excluding import of matplotlib.pyplot from module IPython.core.pylabtools
46440 INFO: Excluding import of matplotlib._pylab_helpers from module IPython.core.pylabtools
46440 INFO: Excluding import of matplotlib.figure from module IPython.core.pylabtools
46443 INFO: Excluding import of matplotlib.backend_bases from module IPython.core.pylabtools
46444 INFO: Excluding import of matplotlib from module IPython.core.pylabtools
46450 INFO: Excluding import of PySide from module IPython.external.qt_loaders
46456 INFO: Excluding import of PyQt4 from module IPython.external.qt_loaders
46462 INFO: Loading module hook 'hook-jedi.py' from 'C:\Users\PC\anaconda3\lib\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks'...
47510 INFO: Loading module hook 'hook-jinja2.py' from 'C:\Users\PC\anaconda3\lib\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks'...
47588 INFO: Loading module hook 'hook-jsonschema.py' from 'C:\Users\PC\anaconda3\lib\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks'...
47605 INFO: Loading module hook 'hook-nbconvert.py' from 'C:\Users\PC\anaconda3\lib\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks'...
47702 INFO: Loading module hook 'hook-nbformat.py' from 'C:\Users\PC\anaconda3\lib\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks'...
47753 INFO: Loading module hook 'hook-netCDF4.py' from 'C:\Users\PC\anaconda3\lib\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks'...
47776 INFO: Loading module hook 'hook-notebook.py' from 'C:\Users\PC\anaconda3\lib\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks'...
50231 INFO: Loading module hook 'hook-osgeo.py' from 'C:\Users\PC\anaconda3\lib\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks'...
50237 INFO: Loading module hook 'hook-pycparser.py' from 'C:\Users\PC\anaconda3\lib\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks'...
50238 INFO: Loading module hook 'hook-pytest.py' from 'C:\Users\PC\anaconda3\lib\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks'...
50944 INFO: Loading module hook 'hook-shapely.py' from 'C:\Users\PC\anaconda3\lib\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks'...
50945 INFO: Loading module hook 'hook-zmq.py' from 'C:\Users\PC\anaconda3\lib\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks'...
51160 INFO: Loading module hook 'hook-difflib.py' from 'C:\Users\PC\anaconda3\lib\site-packages\PyInstaller\hooks'...
51168 INFO: Excluding import of doctest from module difflib
51168 INFO: Loading module hook 'hook-distutils.py' from 'C:\Users\PC\anaconda3\lib\site-packages\PyInstaller\hooks'...
51170 INFO: Loading module hook 'hook-distutils.util.py' from 'C:\Users\PC\anaconda3\lib\site-packages\PyInstaller\hooks'...
51176 INFO: Excluding import of lib2to3.refactor from module distutils.util
51176 INFO: Loading module hook 'hook-encodings.py' from 'C:\Users\PC\anaconda3\lib\site-packages\PyInstaller\hooks'...
51247 INFO: Loading module hook 'hook-heapq.py' from 'C:\Users\PC\anaconda3\lib\site-packages\PyInstaller\hooks'...
51253 INFO: Excluding import of doctest from module heapq
51253 INFO: Loading module hook 'hook-importlib_metadata.py' from 'C:\Users\PC\anaconda3\lib\site-packages\PyInstaller\hooks'...
51255 INFO: Loading module hook 'hook-lib2to3.py' from 'C:\Users\PC\anaconda3\lib\site-packages\PyInstaller\hooks'...
51288 INFO: Loading module hook 'hook-matplotlib.backends.py' from 'C:\Users\PC\anaconda3\lib\site-packages\PyInstaller\hooks'...
51835 INFO: Matplotlib backend "GTK": ignored
Gtk* backend requires pygtk to be installed.
52213 INFO: Matplotlib backend "GTKAgg": ignored
Gtk* backend requires pygtk to be installed.
52490 INFO: Matplotlib backend "GTKCairo": ignored
No module named 'gtk'
52865 INFO: Matplotlib backend "GTK3Agg": ignored
The Gtk3 backend requires PyGObject or pgi
53146 INFO: Matplotlib backend "GTK3Cairo": ignored
cairo backend requires that cairocffi or pycairo is installed
53528 INFO: Matplotlib backend "MacOSX": ignored
cannot import name '_macosx' from 'matplotlib.backends' (C:UsersPCanaconda3libsite-packagesmatplotlibackends\__init__.py)
54360 INFO: Matplotlib backend "nbAgg": added
54807 INFO: Matplotlib backend "Qt4Agg": added
55075 INFO: Matplotlib backend "Qt4Cairo": ignored
cairo backend requires that cairocffi or pycairo is installed
55500 INFO: Matplotlib backend "Qt5Agg": added
55775 INFO: Matplotlib backend "Qt5Cairo": ignored
cairo backend requires that cairocffi or pycairo is installed
56173 INFO: Matplotlib backend "TkAgg": added
56464 INFO: Matplotlib backend "TkCairo": ignored
cairo backend requires that cairocffi or pycairo is installed
56927 INFO: Matplotlib backend "WebAgg": added
57299 INFO: Matplotlib backend "WX": ignored
Matplotlib backend_wx and backend_wxagg require wxPython>=2.9
57565 INFO: Matplotlib backend "WXAgg": ignored
No module named 'wx'
57833 INFO: Matplotlib backend "WXCairo": ignored
No module named 'wx'
58209 INFO: Matplotlib backend "agg": added
58481 INFO: Matplotlib backend "cairo": ignored
cairo backend requires that cairocffi or pycairo is installed
58755 INFO: Matplotlib backend "gdk": ignored
No module named 'gobject'
59136 INFO: Matplotlib backend "pdf": added
59582 INFO: Matplotlib backend "pgf": added
59958 INFO: Matplotlib backend "ps": added
60338 INFO: Matplotlib backend "svg": added
60714 INFO: Matplotlib backend "template": added
61019 INFO: Loading module hook 'hook-matplotlib.py' from 'C:\Users\PC\anaconda3\lib\site-packages\PyInstaller\hooks'...
61304 INFO: Loading module hook 'hook-multiprocessing.util.py' from 'C:\Users\PC\anaconda3\lib\site-packages\PyInstaller\hooks'...
61309 INFO: Excluding import of test from module multiprocessing.util
61310 INFO: Excluding import of test.support from module multiprocessing.util
61310 INFO: Loading module ho