Python QT app Standalone App conversion memo

I needed to turn the python app into a standalone app, so I did a lot of research. There were various conversion tools, but in the end I decided to use pyinstaller. By the way, using qtcreator makes it really easy to create a GUI. (It costs money after the free period.)

OUTLINE --Environment --Create an environment with pyenv


environment

MacOSX El Capitan 10.11.5   
python3.5.0 (homebrew pyenv-virtualenv)   
qt5,pyqt5 (homebrew)    

I feel that there are many people who manage the python version with pyenv in the mac environment, and there are many people who put pyenv and qt with homebrew, but even if I look for a set of information, it comes out quite easily. There wasn't.

Create an environment with pyenv

When I try to use pyinstaller with python3.5.0 which I put in pyenv without thinking about anything I don't have libpython3.4.dylib! Error. It seems that python must be included as a framework. I had to be careful about compiling and install python.

env PYTHON_CONFIGURE_OPTS="--enable-framework" pyenv install -v 3.5.0
~I'm going to do various things.~
pyenv virtualenv 3.5.0 stand_app

And this too.

pip install --upgrade pip

PyQt5 Install for the time being

brew install pyqt5 --with-python

It seems that pyqt cannot be installed with pip, so pyqt5 installed with brew can be used by symbolically linking it to the pyenv environment.

ln -s /usr/local/Cellar/pyqt5/5.6/lib/python3.5/site-packages/PyQt5/ /usr/local/opt/pyenv/versions/stand_app/lib/python3.5/site-packages/

You can use it for the time being. It's a little bit harsh. ..

pyinstaller pyinstaller can be installed from pip.

pip install pyinstaller

Create qt application

For the time being, write a simple qt app.

Save the following as qt.py


import sys
from PyQt5.QtWidgets import (QWidget, QToolTip,
    QPushButton, QApplication)
from PyQt5.QtGui import QFont
from PyQt5.QtCore import QCoreApplication


class Example(QWidget):
  def __init__(self):
      super().__init__()

      self.initUI()


  def initUI(self):

      QToolTip.setFont(QFont('SansSerif', 10)) #font-Specifying family and font size
      self.setToolTip('This is a <b>QWidget</b> widget')#Insert a tooltip with the mouse on.

      btn = QPushButton('Button', self) #Button generation
      btn.setToolTip('This is a <b>QPushButton</b> widget') #Insert a tooltip with the mouse on.
      btn.clicked.connect(QCoreApplication.instance().quit) #Press the button to close the screen
      btn.resize(btn.sizeHint()) #It specifies a nice button size and button effect.
      btn.move(50, 50)#Button position setting

      self.setGeometry(300, 300, 300, 200)
      self.setWindowTitle('Tooltips')
      self.show()

if __name__ == '__main__':

    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())

standalone app generation

And finally this is the one I've been waiting for. From the command line

pyinstaller --onefile --windowed qt.py

Dorya. ./dist/ qt.app Can be done! !! !! !!

I did it! !!

Recommended Posts

Python QT app Standalone App conversion memo
Qt for Python app self-update
Python memo
python memo
Python memo
python memo
Python memo
Python memo
Python memo
Python UTC ⇔ JST, character string (UTC) ⇒ JST conversion memo
Make Qt for Python app a desktop app
[Python] Memo dictionary
python beginner memo (9.2-10)
python beginner memo (9.1)
★ Memo ★ Python Iroha
[Python] EDA memo
Python 3 operator memo
[My memo] python
Python3 metaclass memo
[Python] Basemap memo
Python beginner memo (2)
[Python] Numpy memo
[Python] Conversion memo between time data and numerical data
Python class (Python learning memo ⑦)
My python environment memo
python openCV installation (memo)
Python module (Python learning memo ④)
Python test package memo
[Python] Memo about functions
python regular expression memo
Binary search (python2.7) memo
[My memo] python -v / python -V
Python3 List / dictionary memo
[Memo] Python3 list sort
Python Tips (my memo)
[Python] Memo about errors
DynamoDB Script Memo (Python)
Python basic memo --Part 2
python recipe book Memo
python unix-time <-> datetime conversion
Basic Python command memo
Python OpenCV tutorial memo
Python basic grammar memo
TensorFlow API memo (Python)
python useful memo links
Python decorator operation memo
Python basic memo --Part 1
Effective Python Memo Item 3
Divisor enumeration Python memo
Python memo (for myself): Array
Python exception handling (Python learning memo ⑥)
Python execution time measurement memo
Twitter graphing memo with Python
[Line / Python] Beacon implementation memo
Python and ruby slice memo
Python Basic Grammar Memo (Part 1)
Python code memo for yourself
Raspberry Pi + Python + OpenGL memo
Python basic grammar (miscellaneous) Memo (3)
Python immutable type int memo
Python memo using perl --join