Python Forum
Compile python project to single portable .exe file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Compile python project to single portable .exe file
#1
I would like compile python project to one exe file.

I installed python 3.6, pygt5 and pyinstaller.

I can run script with python interpreter using command 'python name.py' and compile scritpt to exe file using command 'pyinstaller --onefile name.py'

But unfortunettly, when compiled file (exe file) is ran (by mouse click), also the console window appears.

#!/usr/bin/python3
# -*- coding: utf-8 -*-

from PyQt5.QtWidgets import QApplication, QWidget


class Calculator(QWidget):
    def __init__(self, parent=None):
        super().__init__(parent)

        self.interfejs()

    def interfejs(self):

        self.resize(300, 100)
        self.setWindowTitle("Simple calculator")
        self.show()


if __name__ == '__main__':
    import sys

    app = QApplication(sys.argv)
    window = Calculator()
    sys.exit(app.exec_())
It is application with gui and I would like open only gui (without cmd window).

.
Reply
#2
https://pyinstaller.readthedocs.io/en/st...ic-options

use
Quote:-w, --windowed, --noconsole Windows and Mac OS X: do not provide a console window for standard i/o. On Mac OS X this also triggers building an OS X .app bundle. This option is ignored in *NIX systems.

Also you may want to rename your file and use .pyw extension
Reply
#3
(Dec-05-2017, 09:59 AM)buran Wrote: use
Quote:-w, --windowed, --noconsole Windows and Mac OS X: do not provide a console window for standard i/o. On Mac OS X this also triggers building an OS X .app bundle. This option is ignored in *NIX systems

Thanks,

I have another question

I also try compile greater project (electrum) and after 'pyinstaller --onefile --noconsole electrum' and run electrum.exe file in dist directory I got error:

Quote:Traceback (most recent call last):
File "electrum", line 373, in <module>
File "site-packages\electrum-3.0.2-py3.6.egg\electrum\daemon.py", line 282, in init_gui
ModuleNotFoundError: No module named 'electrum_gui'
[5556] Failed to execute script electrum

(in the interpreter it starts correctly)

in README file, I found following information:

Quote:Development version
===================

1. Check out the code from Github::

git clone git://github.com/spesmilo/electrum.git
cd electrum

2. Run install (this should install dependencies)::

python3 setup.py install

3. Compile the icons file for Qt::

sudo apt-get install pyqt5-dev-tools
pyrcc5 icons.qrc -o gui/qt/icons_rc.py

4. Compile the protobuf description file::

sudo apt-get install protobuf-compiler
protoc --proto_path=lib/ --python_out=lib/ lib/paymentrequest.proto

5. Create translations (optional)::

sudo apt-get install python-pycurl gettext
./contrib/make_locale

Creating Binaries
=================

To create binaries, create the 'packages' directory::

./contrib/make_packages

This directory contains the python dependencies used by Electrum.

(...)

Windows
-------

See contrib/build-wine/README file.

i executed 'python setup.py install' and ' pyrcc5 icons.qrc -o gui/qt/icons_rc.py'

but command 'protoc --proto_path=lib/ --python_out=lib/ lib/paymentrequest.proto' (fourth step in above instruction) is not recognized.

I cannot use apt-get because I work on windows.

'pip install protobuf-compiler' doesnt work.

How I can install "protobuf-compiler" and is it necessary to solve my problem ?
Reply
#4
There are specific instructions for installation under windows - as an executable or from python source. The development version that is developed in linux?
Reply
#5
(Dec-05-2017, 11:08 AM)buran Wrote: There are specific instructions for installation under windows - as an executable or from python source.

But this "specific instruction" is totally unhelpful for me.

In README file was written:

Quote:Creating Binaries
=================


To create binaries, create the 'packages' directory::

./contrib/make_packages

This directory contains the python dependencies used by Electrum.

Mac OS X / macOS
--------

(...)

Windows
-------

See contrib/build-wine/README file.

Android
-------

(...)

but the file "contrib/build-wine/README " does not exist !
Reply
#6
I refer to information from this link
https://electrum.org/#download

as to the contrib/build-wine/README that is for linux. wine allows to run windows programs on linux OS. the file is available in the github repo that you provide link for https://github.com/spesmilo/electrum/tre...build-wine

i.e. that is how to compile windows binary on linux machine
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Web project and running a .py file emont 0 639 Dec-11-2022, 11:15 PM
Last Post: emont
  python sql query single quote in a string mg24 1 1,062 Nov-18-2022, 08:01 PM
Last Post: deanhystad
  python Multithreading on single file mg24 3 1,728 Nov-05-2022, 01:33 PM
Last Post: snippsat
  Create multiple/single csv file for each sql records mg24 6 1,389 Sep-29-2022, 08:06 AM
Last Post: buran
  How to compile a Python script for a Windows / Linux executable? netanelst 2 1,319 May-24-2022, 07:02 AM
Last Post: netanelst
  Setup Portable Python on Windows for script starts with double clicks? pstein 0 1,813 Feb-18-2022, 01:29 PM
Last Post: pstein
  cv2-python will n ot compile?? barryjo 5 2,189 Dec-26-2021, 06:42 PM
Last Post: barryjo
  [SOLVED] Input parameter: Single file or glob? Winfried 0 1,582 Sep-10-2021, 11:54 AM
Last Post: Winfried
  help with project of reading and searching big log file korenron 6 2,169 Jun-24-2021, 01:57 PM
Last Post: korenron
  Python Compile error ajitnayak1987 4 3,639 Jun-03-2021, 12:11 PM
Last Post: ibreeden

Forum Jump:

User Panel Messages

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