So my project is python-based, and I have already created the .exe file for it using pyinstaller.
Now I have a folder containing,
main.exe file
README.txt
I am able to make a single executable file, that will install the dependencies related to main.exe, using NSIS. But for my project to run properly, I need to install another software called GhostScript.
I was wondering if there is a way to do so in NSIS itself. Like when it installs the dependencies it automatically installs GhostScript too.
NOTE: It's for a Windows app
Ghostscript also uses NSIS so it supports the same silent install switch as other NSIS installers.
InstallDir "$ProgramFiles\MyApp"
RequestExecutionLevel Admin
Page Components
Page Directory
Page InstFiles
!include LogicLib.nsh
Section "Ghostscript"
InitPluginsDir
File "/oname=$pluginsdir\gsinst.exe" "gs9540w32.exe"
ExecWait '"$pluginsdir\gsinst.exe" /S' $0
${If} $0 <> 0
MessageBox mb_iconstop "Unable to install Ghostscript!"
Abort
${EndIf}
SectionEnd
Section
SetOutPath $InstDir
File main.exe
File Readme.txt
SectionEnd
Context:
I am developping a simple Python application using a PySide2 GUI. It currently works fine in Windows, Linux and Mac. On Windows, I could use PyInstaller and InnoSetup to build a simple installer. Then I tried to do the same thing on Mac. It soon broke, because the system refused to start the command or the app generated by PyInstaller because it was not correctly signed. And as I am not an apple developper, I cannot sign anything...
After some research, I tried py2app. I can go one step further here. With
python setup.py py2app -A
I can create a runnable app. Which obviously cannot be ported to a different system because it uses my development folders. And if I use python setup.py py2app the generated program cannot start because py2app did not copy all the required Qt stuff. I tried to add one by one the missing libraries, but on the end the system could not find the plugins and I gave up...
Question:
Can someone help me with a recipe to convert a python script or package using a Qt GUI into a portable app on Mac? Ideally, the recipe should say how to use a custom application icon, but this is not required.
References:
Python 3.8.5
macOS 10.15.7 Catalina
PySide2 5.15.1
PyInstaller 4.0
py2app 0.22
As my real package is too large for a SO question I trimmed it down to a minimal reproducible example:
from PySide3.QtWidgets import *
import sys
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
hello = QLabel('Hello', self)
hello.move(50, 50)
def run(args):
app = QApplication(args)
main = MainWindow()
main.show()
sys.exit(app.exec_())
if __name__ == '__main__':
run(sys.argv)
And here is the setup.py file used for py2app:
from setuptools import setup
APP = ['app.py']
DATA_FILES = []
OPTIONS = {}
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
Requirements
works with Python 3.8.5
macOS 10.15.7 Catalina
uses PySide2 and py2app
Problems
PySide2 must be added under OPTIONS to the packages list
when running the app then still an error occurs: Library not loaded: #rpath/libshiboken2.abi3.5.15.dylib, Reason: image not found
Solution
The slightly modified setup.py could look like this:
from setuptools import setup
APP = ['app.py']
DATA_FILES = []
OPTIONS = {
'packages': ['PySide2'],
'iconfile': 'some_icon.icns',
'plist': {
'CFBundleDevelopmentRegion': 'English',
'CFBundleIdentifier': "com.ballesta.xxx",
'CFBundleVersion': "1.0.0",
'NSHumanReadableCopyright': u"Copyright © 2020, Serge Ballesta, All Rights Reserved"
}
}
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
Additionally, an icon definition and a few plist entries for some basic information have been added.
The whole build is best triggered with a script that could look like this:
#!/bin/sh
python3 -m venv venv
. venv/bin/activate
pip install PySide2
pip install py2app
python setup.py py2app
cp ./venv/lib/python3.8/site-packages/shiboken2/libshiboken2.abi3.5.15.dylib ./dist/app.app/Contents/Resources/lib/python3.8/lib-dynload/shiboken2
Test
Here the screenshot of a test run:
I think what you're missing is the inclusion of the Python3 Framework in your application bundle. I've developed a simple macOS app myself recently, however I wanted to have a little more insight on how to do so, so I did a bit of digging into the actual structure of an application. Basically, you are going to put everything into a normal folder with the name of your application. Call this folder MyApp. Inside this folder we'll have another called Contents. From my understanding, py2app just takes all of the things that make up your app, and structures them inside of this folder as well as creates an Info.plist file, which also goes inside of Contents. So far, here is what you have:
MyApp
-> Contents
-> -> Info.plist
In addition to the Info.plist file with all of the necessary properties, in your Contents folder you will have a MacOS folder and a Resources folder at minimum. Your issue is that you also need a Frameworks folder, where you would add the required version of Python.
Now, your app hierarchy should look like:
MyApp
-> Contents
-> -> Info.plist
-> -> MacOS
-> -> Resources
-> -> Frameworks
In the Frameworks folder, you can put the full Python 3 framework you're working with to build the app, as well as any site-packages that you require to run the application, and then you can reflect all of those changes in the executable so that you are pointing to the correct installations.
To my understanding, all that's necessary to make the application functional on MacOS is to ensure that your main executable is placed in the MacOS folder and points to the Python located in your Frameworks folder, your icon .icns file is placed in the Resources folder, and your Info.plist file is built.
In order for MacOS to recognize it as a full application, I believe you possibly need to use productbuild and include a Developer license certificate, but it's really only necessary if you want the application to be distributed. Otherwise, I just added the extension .app to MyApp, which converts it into an application.
Without the above-mentioned license/certificate whatever, it probably won't recognize that it should find your icon file and add it, so if you open it in Preview, select-all, and copy it, you should be able to right-click on the application, press 'Get Info', and paste the icon on top of the current icon in the window to make it display correctly.
EDIT: My resources for learning about making macOS apps:
Bundle structure
Including frameworks
Signing your application
productbuild manpage
If you want to package for OSX, you should either
Create a Brew Tap
This probably makes the most sense for an open source developer
General Instructions https://docs.brew.sh/How-to-Create-and-Maintain-a-Tap
host your code in git (does not need to be GitHub)
create a Formula (Formula Cookbook)
fork homebrew-core on GitHub
add your Formula and create a pull request to get it into the main repo
support your pull request such that it is completed
Join the Apple Developer Program
This probably makes the most sense for a closed source developer
Overview: https://developer.apple.com/programs/how-it-works/
This program costs 99USD annually, but will allow you to sign your package/final binary and distribute it yourself or on their App Store
After creating your account, here's a guide for packaging and signing for OSX https://developer.apple.com/forums/thread/128166
structure your code to support signing (add a build step to copy your work into a clean path to avoid frustrating rework)
% codesign -s <Developer ID Application signing identity> /path/to/code
pick a storage format (.zip, .dmg, .pkg) and bundle your application as it
After fiddling around a lot with the different options to build a macOS bundle for a PySide2 application I found the following steps to work pretty much out of the box.
This recipe using pyinstaller to create a macOS app bundle was tested with Python 3.9.1, PySide2 5.15.2, pyinstaller 4.2 on macOS Catalina 10.15.7.
Install pyenv and latest Python with Framework support (see Pyenv, How to manage multiple Python versions and virtual environments for a general introduction into how pyenv works):
brew install pyenv
PYTHON_CONFIGURE_OPTS="--enable-framework" pyenv install 3.9.1
Create a folder for the example, create an example pyside application:
mkdir hello && cd hello
nano hello.py
hello.py:
import sys
from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtWidgets import *
class MainWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
self.setWindowTitle("Hello World")
self.button = QPushButton("Click me")
self.button.clicked.connect(self.say_hello)
self.setCentralWidget(self.button)
#Slot()
def say_hello(self, url):
self.button.setText("Hello!")
if __name__ == "__main__":
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())
Create a venv for the project, install python packages:
pyenv local 3.9.1
python3 -m venv venv
source venv/bin/activate
pip install pip pyside2 pyinstaller --upgrade
Try running the app using the python interpreter:
python3 hello.py
Create a macos app bundle:
pyinstaller --windowed hello.py
Run the app using the app bundle:
open dist/hello.app
Check out the generated hello.spec for the build configuration, re-build the app with pyinstaller hello.spec.
I have successfully build apps using fbs.
It is intended to build Python+PyQt5 apps (you can also use PySide2) and it should work on Mac OS as well (according to the documentation/tutorial).
Using PyInstaller it failed very often for including PyQt5 dependencies (especially when I was working with pyqtgraph), but with fbs it works great.
I think the solution to your problem can be found here. First, create a virtual environment and install all modules to the same virtual environment.
mkvirtualenv --python="PATH/TO/PYTHON3.6.5/python.exe" venv
Install Qt framework
# Install qt via homebrew
brew install qt
# Switch to version 5.11.1
brew switch qt 5.11.1
# Do this to link qmake with qt
brew link qt5 --force
Then, install the PySide2
git clone --recursive https://code.qt.io/pyside/pyside-setup
After that,
cd pyside-setup && git checkout 5.11
Build, and install PySide2 and make sure to set the path of QMAKE that comes with the Qt installation
#To get the path
which qmake
# Make sure that your virtual environment is activated
# Build PySide2 from source
python setup.py install --qmake=<PATH/TO/QMAKE> --build-tests --ignore-git --jobs=8
# Install PySide2
python setup.py build --qmake=/path/to/qmake --build-tests --ignore-git --jobs=8
Update
First, make sure that you run your code in the same virtual environment, and to convert it to a standard mac OS app you can use py2app or pyinstaller . Also, try to downgrade your py2app if it is not working with your current version after you follow the same process.
sudo easy_install py2app
#or
pip install -U git+https://github.com/metachris/py2app.git#master
Create setup.py
py2applet --make-setup app.py
Wrote setup.py
and you have to create a config file or see this example and include any file that you have
from setuptools import setup
APP = ['app.py']
DATA_FILES = []
OPTIONS = {
'argv_emulation': True,
'iconfile': 'app.icns'
}
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
To build the application use
python setup.py py2app -A
To run the app you have to use this way
./dist/app.app/Contents/MacOS/app
If it is work with python setup.py py2app -A that means that everything is going ok and you need to use
rm -rf build dist
python setup.py py2app
If any things go wrongs please refer to these references1, 2, and 3. Also, there are alternatives ways to convert your app to os.
After I read your comment, I tried to see what is the problem and I found this and it may solve the problem or you can use alternatives tools such as bbFreeze, pyInstaller or cx_Freeze
I have OPENCV 2.4.10 and CUDA 7.5 installed on Ubuntu 14.4 LTS.
By running a simple python code which uses opencv libraries through terminal,it works well without any problem, but when I make a Pydev Project in eclipse and make a new source python file and paste the above code in it, after running it in eclipse gives the following error.
ImportError: libnppc.so.7.0: cannot open shared object file: No such file or directory
this is the paths in .bashrc file:
# added by Anaconda 2.3.0 installer
export PATH="/home/username/anaconda/bin:$PATH"
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PATH="/usr/local/cuda-7.0/bin:$PATH"
export PATH="/usr/local/cuda/bin:$PATH"
export LD_LIBRARY_PATH="/usr/lib/:$LD_LIBRARY_PATH"
export LD_LIBRARY_PATH="/usr/local/lib:$LD_LIBRARY_PATH"
export LD_LIBRARY_PATH="/home/username/anaconda/lib:$LD_LIBRARY_PATH"
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH="/usr/local/cuda-7.0/lib64:$LD_LIBRARY_PATH"
export LD_LIBRARY_PATH="/usr/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH"
in eclipse the following path is for Python Interpreter:
/home/username/anaconda/bin
libraries in Cuda-7.0:
$/usr/local/cuda-7.0/lib64$ ls
cudnn.h libcuinj64.so libcublas_device.a
libcuinj64.so.7.0 libcublas.so libnppi_static.a
libcublas.so.7.0 libcuinj64.so.7.0.18 libnpps.so
libculibos.a libnpps.so.7.0 libcublas.so.7.0.18
libcurand.so libcublas_static.a libcurand.so.7.0
libnpps.so.7.0.18 libcudadevrt.a libnpps_static.a
libcudart.so libcurand.so.7.0.18 libnvblas.so
libcudart.so.7.0 libcurand_static.a libnvblas.so.7.0
libcusolver.so libcudart.so.7.0.18 libcusolver.so.7.0
libnvblas.so.7.0.18 libcudart_static.a libnvrtc-builtins.so
libcudnn.so libcusolver.so.7.0.18 libnvrtc-builtins.so.7.0
libcudnn.so.6.5 libcusolver_static.a
libcudnn.so.6.5.48 libcusparse.so libnvrtc-builtins.so.7.0.18
libcudnn_static.a libcusparse.so.7.0 libnvrtc.so
libcufft.so libnvrtc.so.7.0
libcufft.so.7.0 libcusparse.so.7.0.18
libcusparse_static.a libnvrtc.so.7.0.17
libcufft.so.7.0.18 libnppc.so libnvToolsExt.so
libcufft_static.a libnppc.so.7.0 libnvToolsExt.so.1
libcufftw.so libnvToolsExt.so.1.0.0
libcufftw.so.7.0 libnppc.so.7.0.18 libOpenCL.so
libnppc_static.a libOpenCL.so.1
libcufftw.so.7.0.18 libnppi.so
libcufftw_static.a libnppi.so.7.0
I found the solution:
Eclipse is looking for cuda folder not cuda-7.0 folder, so I had do build symbolink links of the libraries in cuda-7.0 in cuda folder as well.
this solved the problem.
I've tried to resolve this prolem for about 3days, and I'd finally felt that I need to ask for help by creating my own question.
I have Windows 7x64 and Qt4.8.6 installed.
I need Python with PyQt and Qscintilla2 to be installed and working.
Now I wil describe my last actions. I did everything like included packages instructions said.
1) Installed Python2.7.9 32bit from official website.
2) Downloaded SIP from here (dev snapshot), then:
configure.py —platform win32-g++
mingw32-make
mingw32-make install
3) Downloaded PyQt from here (not the installer but dev snapshot, cause I need to build with MinGW and istaller producec MSVC version), then:
configure-ng.py -spec win32-g++
mingw32-make
mingw32-make install
Ater these steps I tested PyQt on my project - everything works fine.
Then I starded trying to install Qsnitilla2.
4) Downloaded Qsnitilla2 from here (dev snapshot), then:
a) in Qt4Qt5 folder:
qmake qscintilla.pro -spec win32-g++
mingw32-make
mingw32-make install
This had installed Qsnitilla2 in Qt4.8.6 as I saw;
b) in Python folder( F..ing Python bindngs, excuse my french):
config.py —spec win32-g++
mingw32-make
after this I got ld.exe error (linking error):
Then, afted doing some research, I manually edited my Makefile.Release (by adding -lpython27 to LIBS parameter):
LIBS = -L"c:\Qt-mingw\4.8.6\lib" -LC:\Python27\libs -LC:\Qt-mingw\4.8.6\lib -lqscintilla2 -lQtGui4 -lQtCore4 -lpython27
After this, my mingw32-make completed succesfully. So:
mingw32-make install
This had installed Qscintilla2 Python bindings.
Now I can see Qsci autocomlplete in Eclipse.
So i've tried this:
from PyQt4.Qsci import QsciScintilla
And i've got this in traceback:
from PyQt4.Qsci import QsciScintilla
ImportError: DLL load failed: Не найден указанный модуль
(Translation: The specified module could not be found)
I've tried this with both dev snapshot and src packages from Riverbank website. And also with MinGW 4.8.1 and MinGW-w64 4.8.4. I can't use MinGW-w64 over 4.8 version cause I need boost-1.55 and it only supports MinGW 4.8.
I don't know what to do now, but I really want to use Scintilla in my project. So i'll be very gratefull for any suggestions.
Have you ever tried to load the QsciScintilla right from the console? I mean you need to enter the directory where the QScintilla located( this means current folder is the default folder), then try run the command "from PyQt4.Qsci import QsciScintilla", if this load module failure still happens, this possibly means you need extra dynamic which QScintilla depends, you need to use dll dependency to find out if some other libraries were missing, then put the missing libraries into the same folder of QsciScintilla.
When I compiled Python using PCBuild\build.bat I discovered that several Python external projects like ssl, bz2, ... were not compiled because the compiler did not find them.
I did run the Tools\Buildbot\external.bat and it did download them inside \Tools\ but it looks that the build is not looking for them in this location and the PCBuild\readme.txt does not provide the proper info regarding this.
In case it does matter, I do use VS2008 and VS2010 on this system.
Example:
Build log was saved at "file://C:\dev\os\py3k\PCbuild\Win32-temp-Release\_tkinter\BuildLog.htm"
_tkinter - 2 error(s), 0 warning(s)
Build started: Project: bz2, Configuration: Release|Win32
Compiling...
bz2module.c
..\Modules\bz2module.c(12) : fatal error C1083: Cannot open include file: 'bzlib.h': No such file or
directory
Tools\buildbot\external.bat must be run from py3k root, not from Tools\buildbot\ subdir as you did. Also to build release version of python with Tkinter support you have to edit or copy Tools\buildbot\external.bat to remove DEBUG=1 so it can build tclXY.dll/tkXY.dll (without -g suffix).