Python Forum
Compile python project to single portable .exe file - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Compile python project to single portable .exe file (/thread-6729.html)



Compile python project to single portable .exe file - Campbell - Dec-05-2017

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).

.


RE: Compile python project to single portable .exe file - buran - Dec-05-2017

https://pyinstaller.readthedocs.io/en/stable/usage.html#windows-and-mac-os-x-specific-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


RE: Compile python project to single portable .exe file - Campbell - Dec-05-2017

(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 ?


RE: Compile python project to single portable .exe file - buran - Dec-05-2017

There are specific instructions for installation under windows - as an executable or from python source. The development version that is developed in linux?


RE: Compile python project to single portable .exe file - Campbell - Dec-05-2017

(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 !


RE: Compile python project to single portable .exe file - buran - Dec-05-2017

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/tree/master/contrib/build-wine

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