Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cx Freeze to exe - HELP
#1
Hi everyone,

I made a python app using PyQt5, pandas, folium and stuff but now I struggle to convert it to exe. I tried Auto-to exe / Pyinstaller / Cx freeze, there is nothing to do, It doesn't work.

I decided to keep trying with cx freeze. In order to understand from where the problem come from. I will convert step by step.

At this step, the converted exe code works :

(NB : I need to add fild "plateforms" to folder to make everything work.)

simple.py :

import sys
from PyQt5.QtWebEngineWidgets import QWebEngineView
from PyQt5.QtWidgets import QWidget, QMessageBox, QApplication, QLabel, QListWidget, QPushButton, QDesktopWidget, QMainWindow, QAction, qApp, QApplication, QFileDialog, QTableView, QFrame, QSplitter, QTableWidget, QTableWidgetItem, QHBoxLayout, QVBoxLayout, QGridLayout, QHeaderView, QSizePolicy, QWidget
from PyQt5.QtCore import QAbstractTableModel, Qt, QSize, QUrl
import os


class App(QMainWindow):

    def __init__(self):
        super().__init__()
        self.title = 'TEST'
        self.initUI()
        
    def initUI(self):
        self.setWindowTitle(self.title)
        self.resize(640, 480)
        self.widget = QWidget()
        self.setCentralWidget(self.widget)
        self.setMouseTracking(True)
        self.widget.setMouseTracking(True)
        self.rightClick = False
        self.leftClick = False
        self.statusBar()

        menubar = self.menuBar()
        fileMenu = menubar.addMenu('File')
        fileMenu2 = menubar.addMenu('Tools')
        fileMenu3 = menubar.addAction('Readme')


        self.table_view = QTableView(self.widget)
        self.table_view.show()


        self.vbox = QVBoxLayout(self.widget)
        self.vbox.addWidget(self.table_view)
        self.widget.setLayout(self.vbox)

        self.show()
       
    
if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = App()
    sys.exit(app.exec_())
Setup.py:

from cx_Freeze import setup, Executable
from PyQt5.QtWebEngineWidgets import QWebEngineView
from PyQt5.QtWidgets import QWidget, QMessageBox, QApplication, QLabel, QListWidget, QPushButton, QDesktopWidget, QMainWindow, QAction, qApp, QApplication, QFileDialog, QTableView, QFrame, QSplitter, QTableWidget, QTableWidgetItem, QHBoxLayout, QVBoxLayout, QGridLayout, QHeaderView, QSizePolicy, QWidget
from PyQt5.QtCore import QAbstractTableModel, Qt, QSize, QUrl
import os
import sys


path = sys.path

base = None

if sys.platform == "win32":
    base = "Win32GUI"

if sys.platform == 'win64':
    base = "Win64GUI"

packages = ['sys', 'os']

include_files = ['map.html']

include = ["PyQt5", "atexit"]

options = {'build_exe': {'packages':packages,'include_files':include_files, 'includes':include}}


executables = [
    Executable('simple.py', base=base)
]

setup(name='Mapping',
      version='0.1',
      description='Visualisation de données sur une carte',
      options=options,
      executables=executables
      )
Next step, I add QWebview widget to simple.py

self.webview = QWebEngineView(self.widget)

def find_data_file(filename):
    if getattr(sys, 'frozen', False):
       datadir = os.path.dirname(sys.executable)
    else:         
       datadir = os.path.dirname(__file__)
    return os.path.join(datadir, filename)

path = find_data_file("map.html")

filepath = os.path.abspath(path)        
self.webview.load(QUrl.fromLocalFile(filepath))
self.vbox.addwidget(self.webview)
And now, the exe doesn't launch (I launch it, but nothing happens, no error message)

It is not related to path of map.html cause, I tried also with QUrl(www.google.com") instead of using my html file.

Do you have any idea ?

Thank you in advance.
Reply
#2
Run .exe from command line and show us result - there should be traceback what happend. If not try to make .exe with flag, in PyInstaller is debug option:
--log-level LEVEL
Reply
#3
What is the complete code for simple.py put together,then i can do a test.
Line 14 in last code.
self.vbox.addwidget(self.webview)

# I guess it should be capital W
self.vbox.addWidget(self.webview)
I have done many test with Pyinstaller(recommenced) and also Cx freeze,usually get to work for most people that have had trouble with this.
Tested PyQt5, pandas with Pyinstaller before several times with working result.
Reply
#4
Hello, thanks for answers.

When I run it through the console, It shows no error, it launch it, but nothing happens

Here is the simple.py code with webview:

import sys
from PyQt5.QtWebEngineWidgets import QWebEngineView
from PyQt5.QtWidgets import QWidget, QMessageBox, QApplication, QLabel, QListWidget, QPushButton, QDesktopWidget, QMainWindow, QAction, qApp, QApplication, QFileDialog, QTableView, QFrame, QSplitter, QTableWidget, QTableWidgetItem, QHBoxLayout, QVBoxLayout, QGridLayout, QHeaderView, QSizePolicy, QWidget
from PyQt5.QtCore import QAbstractTableModel, Qt, QSize, QUrl
import os


class App(QMainWindow):

    def __init__(self):
        super().__init__()
        self.title = 'TEST'
        self.initUI()
        
    def initUI(self):
        self.setWindowTitle(self.title)
        self.resize(640, 480)
        self.widget = QWidget()
        self.setCentralWidget(self.widget)
        self.statusBar()

        menubar = self.menuBar()
        fileMenu = menubar.addMenu('File')
        fileMenu2 = menubar.addMenu('Tools')
        fileMenu3 = menubar.addAction('Readme')


        self.table_view = QTableView(self.widget)
        self.table_view.show()

        self.webview = QWebEngineView(self.widget)

        def find_data_file(filename):
            if getattr(sys, 'frozen', False):
                datadir = os.path.dirname(sys.executable)
            else:         
                datadir = os.path.dirname(__file__)
            return os.path.join(datadir, filename)

        path = find_data_file("map.html")
        filepath = os.path.abspath(path)        
        self.webview.load(QUrl.fromLocalFile(filepath))

        self.vbox = QVBoxLayout(self.widget)
        self.vbox.addWidget(self.table_view)
        self.vbox.addWidget(self.webview)
        self.widget.setLayout(self.vbox)

        self.show()
       
    
if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = App()
    sys.exit(app.exec_())
Reply
#5
Work for me when test it,simple.py and simple.exe do the same.
Is it suppose to show html in small window under the large?
I do testing it a venv(virtual environment).
# Install
(pyqt_env) G:\div_code\pyqt_env
λ pip install pyqt5 pyinstaller PyQtWebEngine

# Command
(pyqt_env) G:\div_code\pyqt_env
λ pyinstaller --onedir --noconsole --add-data map.html;. simple.py
If build it with --onefile then i needed to manually add map.html to dist folder as it did not find as --onedir dos.
Reply
#6
Hi,

I tried to do it through Pyinstaller as u did. Nothing worked. But when I saw you imported PyQtwebengine alongside PyQt5,I figured out that problem was because the package could not be found. No way to get it properly through Conda.

So I deleted everything (Conda/Python) and reinstalled only python and all module via PIP. bye bye Anaconda.

Then everything worked, not only simple.py but my full app (I got issues with mpl_toolkit and geopandas packages but I could fix them.

So thank you for you help, problem was Anaconda.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Tkinter + Multiprocessing startmap makes UI Freeze sunny9495 4 1,396 Nov-13-2022, 12:49 PM
Last Post: sunny9495
  mpv window freeze before video end rfeyer 18 7,077 Mar-09-2021, 06:12 PM
Last Post: rfeyer
  Install Python 3.8 for EduPython and Cx-Freeze mederic39 1 1,794 Jul-24-2020, 01:24 PM
Last Post: Larz60+
  A software freeze ! HELP ! redorc15 1 1,792 Oct-10-2019, 10:54 PM
Last Post: Larz60+
  cx-Freeze exe doesn't work ammann 1 4,317 Mar-19-2018, 10:58 AM
Last Post: buran
  Pyusb freeze when using Dev.read(nr,nr,timeout=1000) bojane 3 7,521 Jan-11-2017, 10:17 AM
Last Post: bojane

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020