Search code examples
kivypyinstallerpackaging

Kivy PyInstaller very large package size in Linux


I am trying to package a code almost 2kb size for linux using PyIntaller, package size is almost 250mb, according to code there is nothing special is imported. How to reduce this size? i am new to packaging all other codes i tried have same package size, here are my imports.

from kivy.app import App
from kivy.uix.widget import Widget
from kivy.graphics import Color, Line
from kivy.uix.floatlayout import FloatLayout
import math
from math import cos, sin, pi
from kivy.clock import Clock
from kivy.lang import Builder
from kivy.properties import NumericProperty
import datetime

Solution

  • You could try running pyinstaller in a different virtual environment.

    To do so on Linux.

    1. Install virtualenv
    2. In a shell:

      • Create an environment with virtualenv env_name - This will create a "env_name" folder in your home directory

      • Activate the virtual environment with source activate env_name

      • Now you are in an environment whith no installed libraries

      • Install cython with pip install cython==0.26 - Latest version is 0.27.3, but kivy 1.10 failed to compile while using that, this could change in the future
      • Install kivy with pip install kivy
      • Install pyinstaller and any other dependance of your project
      • Run pyinstaller with env_name/bin/pyinstaller script.py - This is needed since, by running pyinstaller you would use the one in your original python installation

    This should resonably reduce the amount of unneeded libraries in the package, just make sure you don't forget to install anything

    Also, notice i didn't use sudo in the pip install commands, that's because you don't need it inside the virtual environment, and using it could compromise the result