Skip to content

Kivy documents from SK-GLOBAL

PyPI

GitHub issues GitHub forks GitHub stars GitHub license

Coverage Status Build Status Build status

Bountysource Backers on Open Collective Sponsors on Open Collective

Kivy's wiki official page


Kivy introduction

Not found

Kivy - Open source Python library for rapid development of applications that make use of innovative user interfaces, such as multi-touch apps.

In this document, we will focus to how to build simple app and deploy on multi platform. If you have found any issue on this document, please feedback to us by email python@sk-global.biz

Thank you for viewing this document.


Environment preparing

In this session, we will setup python env, git and source manager.

1. Windows ENV - view official

  • Install Python 3.7 (and 2.7 if need)

    • When run the installation file, should check 'Add Python 3.7 to PATH'.
    • To test python, open Windows Powershell and run command py -3 -V (this must show python's version).
  • Install Git

    Git is a version-control system for tracking changes in computer files and coordinating work on those files among multiple people

  • Install Sourcetree

    Sourcetree simplifies how you interact with your Git repositories so you can focus on coding. Visualize and manage your repositories through Sourcetree's simple Git GUI.

  • Install Visual Studio Code IDE:

    • When run the installation file, in step 'Select Additional Tasks' click Add "Open with Code" action to Windows Explorer directory context menu and then click 'Next' and 'Install'.
    • Import custom settings and extensions (looking for a way, it will be more detailed instructions later)
  • Install VirtualEnv (isolated environment for python)

    • Run cmd py -3.7 -m pip install virtualenv
  • To allow running .ps file, run command Set-ExecutionPolicy RemoteSigned -Scope CurrentUser in PowerShell, then type "y" and press Enter.

Use WSL to build android

  • Read this to install.
  • Install build libs, and a Java SDK:

    sudo apt update
    sudo apt upgrade -y
    sudo apt install build-essential ccache git libncurses5 libstdc++6 libgtk2.0-0 libpangox-1.0-0 libpangoxft-1.0-0 libidn11 openjdk-8-jdk unzip zip zlib1g-dev zlib1g pkg-config
    
  • Choose java version 8:

    sudo update-alternatives --config java
    
    There are 2 choices for the alternative java (providing /usr/bin/java).
    
      Selection    Path                                            Priority   Status
    ------------------------------------------------------------
    * 0            /usr/lib/jvm/java-11-openjdk-amd64/bin/java      1101      auto mode
      1            /usr/lib/jvm/java-11-openjdk-amd64/bin/java      1101      manual mode
      2            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1081      manual mode
    
    Press <enter> to keep the current choice[*], or type selection number:
    
  • Install python dev and pip:

    sudo apt install python3-pip python3-dev
    
  • Install Cython and buildozer:

    pip3 install cython git+https://github.com/Thong-Tran/buildozer.git@fix-errors
    

Note:

  • PATH of WSL include Windows's PATH, it may cause some errors(because of this feature). You should add these two lines to ~/.profile file:

    unset PATH
    . /etc/environment
    

    Or add file /etc/wsl.conf (see more) with content:

    [interop]
    appendWindowsPath = false
    
  • Should run adb start-server on Windows before run adb on WSL.

  • When build complete, java don't close. You may kill it manually.

2. MacOS ENV - view official

  • Install Homebrew

    • Run this cmd in Terminal
    /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    
  • Install Python 3.7 (and 2.7 if need)

    • To test python, open Terminal and run command python3 -V (this must show python's version).
  • Install XCode from AppStore (you must have Apple account)

  • Install Sourcetree

  • Install Visual Studio Code IDE:

    • The downloaded file will be .app file, so you should copy it to /Applications then move to Trash file in Downloads folder.
    • Import custom settings and extensions (looking for a way, it will be more detailed instructions later)
  • Install VirtualEnv (isolated environment for python)

    • Run command pip3 install --upgrade virtualenv.
  • Install the requirements of Kivy (you can skip gstreamer if you aren’t going to use video/audio)

    brew install pkg-config sdl2 sdl2_image sdl2_ttf sdl2_mixer gstreamer
    
  • Option to pack mobile app:

    • Navigate to /Applications/Python x.x/ and run in Terminal Install Certificates.command.
    • Install: buildozer fork of Sk-global, dependent of buildtool:
    wget https://bootstrap.pypa.io/get-pip.py
    python get-pip.py --user
    python -m pip install requests sh pbxproj cffi git+https://github.com/Thong-Tran/buildozer.git@fix-errors -U --user
    rm get-pip.py
    
    • The latest java version (default install) will get error when run android sdk, so you need to install Java 8.
    brew tap caskroom/versions
    brew cask install java8
    touch ~/.android/repositories.cfg
    

    And add export JAVA_HOME=$(/usr/libexec/java_home -v 1.8) to file ~/.bash_profile or ~/.profile. Reopen terminal and run java -version to test using the correct version.

3. Linux ENV


Try sample project

We have build sample project for testing Kivy framework. You can try it by clone source code here and make steps in README.md

If you cannot access the above bicbucket, please contact us for assistance (python@sk-global.biz). If you not friendly with bitbucket, please check session "Clone existing project".

Some feature you can try in this project:

  • Pick image from local
  • Translate image to text by GoogleVision
  • Text result was cached in local storage

Create new project

  • Install Kivy project tools and run it.
  • Fill in the required information into the fields and click Create new project. When completed, it's with show:

Not found

  • You can continue to follow these steps or ignore it.
  • Open project folder by VSCode, check if it have folder .vscode and Workspace Setting(settings.json) have "python.pythonPath": "<your name of env>\\Scripts\\python.exe" (Mac is <your name of env>/bin/python). If you don't see, open setting and type python.pythonPath and add full path of VirtualEnv (python.exe)

Clone existing project

  • Open project on Bitbucket, click "Clone"

Not found

  • Choose type and click "Clone in Source"

Not found

  • Or click copy Not found then open Sourcetree press Ctrl+N and paste git link
  • Create VirtualEnv environment in local project folder:

Hint

If you created VirtualEnv before, you can skip this to save storage space.

py -3 -m pip install --upgrade pip wheel setuptools
py -3 -m pip install --upgrade virtualenv
py -3 -m virtualenv .env
.\.env\Scripts\activate
pip3 install --upgrade pip wheel setuptools
pip3 install --upgrade virtualenv
python3 -m virtualenv .env
source ./.env/bin/activate
  • Install requirement packers pip install -r requirements.txt
  • Open project folder by VSCode: check if it have folder .vscode and Workspace Setting(settings.json) have "python.pythonPath": ".env\\Scripts\\python.exe" (Mac is .env/bin/python). If you don't see or use this env, open setting and type python.pythonPath and add full path of your VirtualEnv (python.exe)
  • Run testcase to check it all is OK
pytest
  • Read README.md of project for more detail.

Kivy support