How can I convert my python code into an dmg file that can be installed on MacOS

105 views Asked by At

I have been trying to convert my code into what's like dmg installer(MacOS) that can I can share with my friends who can install my program

First I tried pyinstaller:

by this line of code: pyinstaller --onefile --add-data "assets/images/logo.png:assets/images" app.py

and it creates something like that

enter image description here

and when I double click on it, it works just fine; however, I can't create a dmg file out of it. as it needs something with extension *.app

Additionally, I tried to create the *.app file by using:

pyinstaller --onefile --osx-bundle-identifier=com.example.MyApp --distpath ./dist/MyApp.app app.py but the generated app file doesn't open and says: You can’t open the application “MyApp” because it may be damaged or incomplete.

Lastly, when I tried to share this exec file with my friends, they can't open, it's more like a file with no extension(It actually is I assumed it would be like app.exec like Windows but no)

enter image description here

Py2app I tried to create the .app file with this library, I created the setup.py, but when I run python setup.py py2app" it keeps telling missing modules like that: ImportError: No module named PyInstaller.hooks.hook-PySide6.QtOpenGL``

I kept added it in the include option; but I added a lot till I got bored, I added like 100, but it doesn't stop

from setuptools import setup

APP = ['app.py']
DATA_FILES = []
OPTIONS = {
    'packages': ['Bio', 'loguru', 'numpy', 'pandas', 'PyQt5', 'pytz','PyQt5-Qt5','PyQt5-sip','PyQt6'],
    'includes': ['sip', 'PyQt5.QtCore', 'PyQt5.QtGui', 'PyQt5.QtWidgets','PyQt5.QtMultimediaWidgets',
                 'PyQt6.uic','PyQt5.QtNfc','PyQt6.Qt3DAnimation','PySide6.QtTextToSpeech','distutils.util',
                'PyQt6.QtOpenGLWidgets','repository.GObject','PyQt5.QtWinExtras','PySide2.QtOpenGLFunctions',
               'repository.GstApp','PyQt6.QtDesigner','PySide6.QtSvgWidgets','PyQt6.QtQuick','PyQt5.QtScript','PySide2.QtOpenGL'
                'scipy','PyQt6.QtWebSockets','PyQt6.QtWebEngineWidgets','PySide2.QtWebEngineCore','PyQt6.QtWebEngineCore','PySide2.QtWidgets',
                'PySide6.QtOpenGL','PyQt6.QtRemoteObjects','repository.GstTranscoder','PySide2.QtSvg','PySide6.QtQuickControls2',
                'PySide2.QtDataVisualization','django.core.mail','PySide2.QtTextToSpeech','pandas.io.formats.style','PySide2.QtRemoteObjects'
                'PySide2.QtXml','PyQt5.QtSvg','PySide6.QtWebSockets','PySide6.QtQuickControls2','setuptools.msvc',
                'etree.cElementTree','PySide2.QtCore','repository.GstAudio','PySide2.QtMultimediaWidgets','PySide2.Qt3DCore',
            'PyQt6.QtXml','PyQt6.QtQml','PyQt5.QtXml','PyQt6.QtQuick','repository.GstGL','pandas.plotting','PySide2.QtWebKitWidgets',
        'PySide6.QtUiTools','PySide2.QtWebSockets','repository.GstVulkanXCB','PyQt5.QtRemoteObjects','PySide2.QtTextToSpeech','PyQt5.QtWebChannel',
    'repository.Gio','PyQt6.QtQuick3D','PySide6.QtWebEngineQuick','PySide2.QtNetwork','PySide6.QtQml','PySide6.QtConcurrent',
'PySide2.QtWebEngineCore','PySide6.QtMultimedia','PySide2.QtLocation','repository.GstSdp','PyQt5.QtSensors'],  # Include PyQt5 submodules explicitly
}

setup(
    app=APP,
    data_files=DATA_FILES,
    options={'py2app': OPTIONS,},
    setup_requires=['py2app'],
)

the the problem is that it gives one missing module at a time, and had to rerun to find another missing one. Is there a simpler way?

I just want to share my code that people can install easily

Any other library/software that can automate this process is more than welcomes

1

There are 1 answers

0
headscratch On

I often make Python Apps using PyInstaller but, I'm far from being an expert, I'm only a user...

I do it often enough to make it a One-Click process by having created a Python App to 'create Python Apps'. Now, I just point to the (xxx.py), click Publish then CMD V and hit the enter key. Bingo! Done!

That's background to the answer you want: There are a handfull of options you can declare but, all I use is the Onefile approach - it creates a packaged xxx.app.

It also creates several other files in the Build folder - I delete ALL of them. It also creates the file you show (in the Dist folder) and I delete that too. All I use and share with others is the xxx.app (after I add a png/icon to the file by drag&droping it into the Get_Info panel (at top left of the panel)

Try the One File approach then, if desired learn how to include resource files.

I don't bother including resource files but, I do include them with the xxx.app file (if the resource files are in the same folder as the xxx.app, they get used and thus, no need to include when creating the xxx.app. Thus, the command is shown in screenshot below (red underscore)

enter image description here