Reputation: 1
I have a Kivy application consisting of many Python and KV files. I want to create an executable so that it can be run in Ubuntu by an end user.
https://kivy.org/doc/stable/guide/packaging.html documentation mentions how to package in OS X and Windows, but there is no mention about Linux distributions.
Any help would be appreciated.
Upvotes: 0
Views: 1112
Reputation: 38822
Here is a scheme that I have used. This script creates a .sh
file to run the python/kivy app:
#!/usr/bin/tcsh
set APP_NAME="HandAndFoot"
# setup output
set OUTPUT="${APP_NAME}.sh"
if $#argv > 0 then
set OUTPUT=$argv[1]
endif
echo "output will be to $OUTPUT"
# copy initial part of shell script into output file
cp ${APP_NAME}.basis $OUTPUT
# create a tar file of the Hand And Foot app
rm -f tmp.tar
tar cf app.tar *.py *.kv dropbox-trusted-certs.crt dialogs/*.py dialogs/*.kv dialogs/*.png resources/*.png resources/*.ico resources/default/*.png
# add the uuencoded version of the app to the end of the output file
uuencode app.tar app.tar >> $OUTPUT
chmod 755 $OUTPUT
# How does a file named "0" get created?? Don't know, but this gets rid of it
rm -f 0
The above script creates a HandAndFoot.sh
that contains a tar
of the app. In this case the app is called HandAndFoot
. When the HandAndFoot.sh
is run, it executes the main.py
script of the app.
In addition to the above script, another file (in this case named HandAndFoot.basis
) is required:
#!/bin/bash
APP_NAME="HandAndFoot"
PYTHON="NONE"
# check if python3 is installed
pyvers=$(python3 -V 2>&1)
echo $pyvers
regex="Python 3.*"
if [[ $pyvers =~ $regex ]]
then
PYTHON="python3"
else
# check if python is installed
pyvers=$(python -V 2>&1)
if [[ $pyvers =~ $regex ]]
then
PYTHON="python"
fi
fi
if [[ $PYTHON != "NONE" ]]
then
kivyimport=$(
$PYTHON 2>&1 <<EOF
import kivy
EOF
)
kivyregex=".*Kivy .*"
if ! [[ $kivyimport =~ $kivyregex ]]
then
echo "Python is installed, but Kivy is also required"
echo "Use you package Manager or 'apt-get' to install Kivy"
exit
fi
else
echo "Python and Kivy are not installed, but are required for the $APP_NAME app"
echo "Use your Package Manager or 'apt-get' to install Python and Kivy"
exit
fi
match=$(grep --text --line-number '^PAYLOAD:$' $0 | cut -d ':' -f 1)
payload_start=$((match + 1))
tail -n +$payload_start $0 | uudecode
rm -rf /tmp/$APP_NAME
mkdir /tmp/$APP_NAME
mv app.tar /tmp/$APP_NAME
cd /tmp/$APP_NAME
tar xvf app.tar
$PYTHON main.py &
exit
PAYLOAD:
The final script checks for Python and Kivy installation and runs main.py
if python and kivy are installed. These scripts can be modified for different apps as needed.
Upvotes: 2