Before I start I need to mention important details, several answers as being Pyinstaller the solution, but this is only part of the resolution, what people need to understand is that Pyinstaller does not magically solve everything, this because Linux is not an operating system, Linux is a kernel, there are many operating systems "based" on the Linux kernel (GNU/Linux), that is, there are different distributions and most (if not almost all) are not compatible.
Yes my people, a program compiled in Debian will not work in Centos, despite being a community open-source great yet each group thinks its way, each distro follows a path, and perhaps this division in the community is their evil (but it is speculation on my part).
Besides being written in Python a program created in Pyinstaller will embark the Python of the version of Linux specific for the executable, I will give an example, I used the Pyinstaller in an Ubuntu with a Python that is installed in the system also, what will happen is that Pyinstaller will copy the python executable from the system (or virtualenv) to the "package" generated by Pyinstaller along with an executable version it will generate, so if you try to run it in a Centos or Debian it probably won’t work (even though debian and Ubuntu are "related").
Pyqt5 and basic deploy (for now on Windows only)
All right, I’ll first talk about some basic details, I’ll explain in Windows for now because I am still preparing the environment in my Centos and in my Debian to be able to put details accurately.
I highly recommend that you do the installation via pip
, because then you will have the packages easier to control the packages and even to install them, but before anything I also recommend much that use virtualenv, more details on:
This is because packages used for a version of Pyqt as well as Pyinstaller can change, update and other situations like this, which can cause you to accidentally update an older project, so isolating a version of Pyqt and other packages for a project of this type can be interesting, so moving the machine, updating your global Python, will not affect your project.
To avoid beating around the bush I’m going to the basic explanation with step by step:
Create the project folder, let’s call it exemplo
, can do via explore.exe
right-clicking/mouse "new folder" or via cmd
with the command md exemplo
)
Open the command prompt (if it is not open) and navigate to the folder where you will create the project, in which case it is the folder exemplo
:
cd c:\Foo\Bar\exemplo
This is an example, logical that will type a real, absolute or relative path.
Enter the command:
python -m venv . env
The .env
is a folder, generated by -m venv
, it will contain a copy of the current Python you use
Now it is necessary to start the virtual env, for that still in cmd and folder exemplo
type this:
.env\scripts\activate.bat
Being in the virtual environment now you must install the necessary packages, in case I tried to install the most updated ones, but there was some problem, maybe it is a conflict/bug with Python 3.6 and 3.7, for that I installed specific versions that worked well (of course you can update this as you wish), the commands (necessary packages are):
pip install PyQt5==5.9.2
pip install PyInstaller==3.3.1
Ready the environment is created, to test the Pyqt5 create a file called main.py
and put this content in it:
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(800, 600)
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
After saving the document run it to test:
python main.py
An empty window should be displayed (as it is only an initial example)
Now the moment of deploy
so expected, using Pyinstaller run:
pyinstaller --windowed main.py
This will generate the executable, in the example it will be in the folder c:/Foo/Bar/dist/main
, the whole folder is needed to work.
In Linux and Mac OSX-based environments
Soon I will put examples like Centos and Debian and if possible Mac, at the moment I am somewhat unable, due to be something very laborious, but I already say that to generate an installation package I may have to use what is explained in the following links (I’ll add more as I can):
I don’t know if pyinstaller solves this part, I think it only manages the executable file (stand-alone executable)
Creating an installer
Unfortunately this is not easy, you can create at hand, with Pyinstaller same, or other executable that install, of course this will all be a little loose, so practical solutions are:
The Inno Setup is interesting, I promise to create a small "tutorial" here in the same answer of how to configure the .ini
of it, placing icon and maybe even "scripts" that will be executed at the time of installation (to eventually in a customized way prepare the operating system for something necessary).
The negative! You can explain there what is wrong?
– Wallace Maxters
You will need the python interpreter and dependencies compiled specifically for Windows/Linux. I recommend taking a look at this tool that seems to be able to package everything in one executable. http://www.pyinstaller.org/
– Leo
Take a look at this article, has several options to do what you want ;)
– Tuxpilgrim