Standalone python file on linux.

54 views
Skip to first unread message

Nishanth Ambati

unread,
Sep 6, 2022, 5:56:21 AM9/6/22
to Kivy users support
Hi there,
Just got started with kivy. I am stuck a point whre I am unable to create a standalone python kivy files on linux environment (Ubuntu 22.04.1 LTS). It seems to be easy doing so on an windows env or mac, but cant find a proper procedure for linux. 
Can anyone hep me out by giving a detailed step by step procedure on how to create a standalone python kivy file on my Ubuntu environment ?

Thanks & Cheers

Abdul Rehman

unread,
Sep 6, 2022, 7:01:02 AM9/6/22
to Kivy users support
Hopefully, this guide will be helpful for you to make Kivy files in Ubuntu.
https://kivy.org/doc/stable/guide/lang.html

Here is the sample code

Just install: 
pip install kivy
File name: my_kivy.kv

#:import is_android util.is_android  // way to import modules
<MyLayout>:
orientation: 'vertical'
size: root.width, root.height

GridLayout:
rows: 4

RelativeLayout:
size_hint: 1, 0.8

AndroidCamera:
index: 0
id: a_cam
resolution: self.camera_resolution
allow_stretch: True
play: True
canvas.before:
PushMatrix
Rotate:
angle: -90 if is_android() else 0
origin: self.center
Scale:
x: self.cam_ratio
y: self.cam_ratio
origin: self.center
canvas.after:
PopMatrix

Label:
id: frame_counter
size_hint_y: None
text_size: self.width, None
height: self.texture_size[1]
padding: [10,10]
text: ''

Tomek CEDRO

unread,
Sep 6, 2022, 7:27:15 AM9/6/22
to kivy-...@googlegroups.com
This is the easiest setup (compared to mobile development). I am using
this to develop Kivy apps on FreeBSD.

You either need to have Kivy system packages installed or create a
dedicated Python Virtual Environment, activate it first, then run your
application. Python Virtual Environment allows you to install local
versions of packages when you have no root on the computer (i.e.
remote server) or if you do not want to use and/or modify system wide
packages. You can have multiple Python Virtual Environment each one
dedicated for a given project, each one with a different packages
different versions for testing etc. Quite convenient :-)

I have some scripts to setup and work with the pyvenv environment.
Maybe these could be added to the source tree and extended to ease
Kivy bootstrap :-)
1. Config file (located in scripts/ subdir of my project).
2. Python Requirements file (says what to install into venv).
3. Bootstrap script (setup the Python VEnv, located in scripts/ subdir
of my projects, uses scripts/config).
4. Python Virtual Environment activator script (if you want to play
inside pyvenv by hand).
5. Application launch (if you "just want the app to run"^TM).


1. scripts/config:

#!/bin/sh
PYTHON=python3.9
VENVLOC=$(dirname $(realpath $0))/../python



2. requirements.txt:
pip
virtualenv
cython
kivy[full]==2.1.0
buildozer==1.4.0
kivymd==1.0.2
gitpython



3. scripts/bootstrap.sh (note you will have to add Linux section
according to your distro):
#!/bin/sh
set -e
. $(dirname $(realpath $0))/config
OS=`uname`

echo "=== BOOTSTRAPPING THE KIVY DEVEL ENVIRONMENT ==="

echo "DETECTED OS: $OS"
case $OS in
"darwin" )
echo "== Installing BREW Open-Source Package Manager for macOS =="
if [ ! -e /usr/local/bin/brew ]; then
/bin/bash -c "$(curl -fsSL
https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
else
echo "BREW is already installed, skipping install!"
fi
echo "== Updating BREW =="
brew update
brew upgrade
echo "== Installing utilities with BREW =="
brew install git openssl pkg-config autoconf automake sdl2
sdl2_image sdl2_mixer sdl2_ttf
;;
"FreeBSD" )
echo "== Installing required system packages ==="
sudo pkg update
sudo pkg install git libressl pkgconf autoconf automake sdl2
sdl2_image sdl2_mixer sdl2_ttf
;;
*)
echo "ERROR: Unknown OS $OS! Please install system dependencies by hand!"
echo " Required: git openssl pkgconfig autoconf automake sdl2*"
exit 1
esac

echo "== Setting up local Python VirtualEnv =="
$PYTHON -m venv --copies $VENVLOC
echo "== Activating Python Virtualenv =="
. $VENVLOC/bin/activate
echo "DONE"
echo "== Installing Python Dependencies =="
pip install -U pip
pip install -r requirements.txt

echo "=== ALL IS SET ==="
echo
echo " REMEMBER TO ACTIVATE PYTHON VIRTUAL ENVIRONMENT"
echo " ONCE EACH TIME AT YOUR DEVELOPMENT SESSION START"
echo " ./scripts/venv.sh"


4. scripts/venv.sh:

#!/bin/sh
. $(dirname $(realpath $0))/config
. $VENVLOC/bin/activate
if [ "$SHELL" == *"zsh"* ]; then
$SHELL -f
else
bash
fi



5. apprun.sh:

#!/bin/sh
. python/bin/activate
python main.py


If is always good to read the project Documentation at first:

https://kivy.org/doc/stable/

There is a dedicated section "Getting Started":

https://kivy.org/doc/stable/gettingstarted/index.html

Where you will find a section "Installing Kivy":

https://kivy.org/doc/stable/gettingstarted/installation.html

Have fun! :-)

--
CeDeROM, SQ7MHZ, http://www.tomek.cedro.info
Reply all
Reply to author
Forward
0 new messages