pythonkivypyinstallerexecx-freeze

Python Kivy project is not getting Converted into portable .exe file


I've Created an exe file of my program. It works fine in my desktop. But in another desktop, if I'd only send the exe file, it says, 'No File\Directory named 'login.kv' found'

I need a standalone exe file, which, wherever it is placed or whichever desktop it is placed, without the source code, it should run.

I've Created a Python Kivy Project which consists of Many Files of .py and .kv. Using Pyinstaller I've Created it into an exe File

The line: pyinstaller --onefile --add-data "*.py;." --add-data "*.kv;." login.py It Gets Created into an exe file, and runs good.

But, when I send only the exe file to another desktop it says "No File/Directory named 'login.kv' found".

Tried, pyinstaller, cx_Freeze, Auto Py to Exe...

Is it because that I've returned the kv files like return Builder.load_file('C:/Users/Admin/PycharmProjects/CCV4Project/Main/main.kv')?

If I use absolute path and stuff like,

def resource_path(relative_path):
    try:
        base_path = sys._MEIPASS
    except Exception:
        base_path = os.path.abspath('.')
    return os.path.join(base_path, relative_path)

and return Builder.load_file(self.resource_path('login.kv'))

It searches for the file based on 'its' location.

But, I want an .exe file Which could run my entire project, no matter where it is placed. It basically should be like an app...


Solution

  • You need to use a spec file with pyinstaller to build a kivy app. There are additional files that must be imported and bundled with the app. This is described in the packaging docs. Here is an example spec file, note the paths are dependent on structure of your project. Here is a spec file for a recent project: https://github.com/ElliotGarbus/KivyCythonWinSample/blob/main/inno-pyinstaller/w11-app.spec

    The lines with kivy_deps are critical.