Yes, use the datas section of the pyinstaller spec file to specify the location of the data files.
https://pyinstaller.readthedocs.io/en/stable/spec-files.html#adding-data-files
--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/6ff5ce58-49f3-4eb5-bbb9-b3ff3de786adn%40googlegroups.com.
Here is an example spec file that I use. I create a directory called project_dist and put the spec file there. This is important to understand the paths.
Reading the kivy log is very useful when trying to debug pyinstaller build problems.
I build a single directory build, and use the Inno Setup Compiler to create a Windows Installer. It has a wizard that makes it easy to create an installer. https://jrsoftware.org/isinfo.php
Note the datas section uses a tuple (source file(s), dest dir)
# -*- mode: python -*-
import os
from kivy_deps import sdl2, glew
spec_root = os.path.abspath(SPECPATH)
block_cipher = None
app_name = 'App Name Here'
win_icon = '../Images/app_design_icon.ico'
a = Analysis(['../main.py'],
pathex=[spec_root],
datas=[('../*.kv', '.'),
('../Images/*.png', './Images')],
hiddenimports=['win32timezone'], # this is required for filechooser.
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
[],
exclude_binaries=True,
name=app_name,
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=False,
console=False,
icon=win_icon)
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
*[Tree(p) for p in (sdl2.dep_bins + glew.dep_bins)],
strip=False,
upx=False,
name=app_name)
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/0f521bec-a21b-4136-9954-80d5b8d2bfc0n%40googlegroups.com.
orientation: 'vertical'
canvas:
Rectangle:
source: 'C:/Users/user/Desktop/images.jpg'
size: self.size
pos: self.pos
ScreenManagment:
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/a2ccccf0-f15d-42ce-bf05-497bd7e4860dn%40googlegroups.com.
Yes, you need to add the jpg file to the datas list. There is an issue that the datas entry you have proposed will not work. You will have a different path for the bundled code.
I would recommend you put all of the code in a project directory. Create a subdirectory called images and put all of the images to be used by the program in the images directory. Use relative paths in you code and you can have the same path for the bundled and unbundled code.
Example:
ProjectOne
/ProjectOne
MySpecFile
/images
Main.py
Validation:
orientation: 'vertical'
canvas:
Rectangle:
source: 'images/images.jpg'
size: self.size
pos: self.pos
and datas:
datas = [('../Images/*.jpg', './Images')]
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CABDb-ViTYtV4%2BooKmMtzMV4eh0XwwQKqpfwYa4vprOaxfdPfDw%40mail.gmail.com.
ProjectOne
/raja
image_test_with_exe.spec
/images
image_test_with_exe.py
from kivy.lang import Builder
from kivy.app import App
from kivy.uix.screenmanager import Screen, ScreenManager
from kivy.uix.boxlayout import BoxLayout
import os
import sys
def resource_path(relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
base_path = getattr(sys, '_MEIPASS', os.path.dirname(os.path.abspath(__file__)))
print(os.path.join(base_path, relative_path))
return os.path.join(base_path, relative_path)
Images = resource_path("images.jpg")
kv='''
<Mainscreen>:
Label:
text: 'Select Task '
color: 0,0,0,1 # to change color
font_size: 20
bold: True
underline: True
size_hint: .3,.2
pos_hint: {'center_x':.5, 'center_y':.9}
FloatLayout:
Button:
text: 'User_Setup'
size_hint: .2,.1
pos_hint: {'center_x':.4, 'center_y':.5}
on_release:
root.manager.transition.direction= 'right'
root.manager.current = "First"
<First>:
Label:
text: 'First Screen '
color: 0,0,0,1 # to change color
font_size: 20
bold: True
underline: True
size_hint: .3,.2
pos_hint: {'center_x':.5, 'center_y':.9}
FloatLayout:
Label:
markup: True
text: 'you clicked [b][color=3333ff][i][size=30]"user_setup button..."[/size][/i][/b][/color]' # changing to italic style
font_size: 20
Button:
text: 'Back'
size_hint: .2,.1
pos_hint: {'center_x':.4, 'center_y':.3}
on_release:
root.manager.transition.direction= 'left'
root.manager.current = "Main"
# Window opens with below code to work with
mailIdValidation:
orientation: 'vertical'
canvas:
Rectangle:
source: 'images/images.jpg'
size: self.size
pos: self.pos
ScreenManagment:
id: sm
Mainscreen:
name: 'Main'
First:
name: 'First'
'''
class ScreenManagment(ScreenManager):
pass
class Mainscreen(Screen):
pass
class First(Screen):
pass
class mailIdValidation(BoxLayout):
def __init__(self, **kwargs):
super().__init__(**kwargs)
#images = self.resource_path()
#def resource_path(self, relative_path):
'''def resource_path(self):
""" Get absolute path to resource, works for dev and for PyInstaller """
base_path = getattr(sys, '_MEIPASS', os.path.dirname(os.path.abspath(__file__)))
#print(os.path.join(base_path, relative_path))
print(base_path)
return base_path #os.path.join(base_path, relative_path)'''
class MainApp(App):
def build(self):
return Builder.load_string(kv)
MainApp().run()
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/60a507ce.1c69fb81.7cd1d.61fbSMTPIN_ADDED_MISSING%40gmr-mx.google.com.
Do a single directory build. See if the structure is what you expect. Do you see the created images dir.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CABDb-ViR0xEEKNFOuDg468YREhLnXM-6qT%2BckjeGESguWistgw%40mail.gmail.com.
def resourcePath():
'''Returns path containing content - either locally or in pyinstaller tmp file'''
if hasattr(sys, '_MEIPASS'):
return os.path.join(sys._MEIPASS)
return os.path.join(os.path.abspath("."))To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/60a69844.1c69fb81.99849.618dSMTPIN_ADDED_MISSING%40gmr-mx.google.com.
For all of my kivy apps I do a one directory build and use the Innosoft setup compiler to build a windows installer. It has a wizard is easy to use, and provides a professional looking windows installer, and the app can be uninstalled from App/Settings in Windows. https://jrsoftware.org/isinfo.php
I did a one exe build of a tkinter based app years ago… and did something similar to your resource code. I need to go to a different machine to see if I can find that code, If I can I will send it along.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CABDb-VhwTB_%2BZB--wQ%2B7D3Nfn2TjVcqfxn_Vrewq3eu7xR8YuQ%40mail.gmail.com.
Here is the relevant code from an old one file build.
if getattr(sys, 'frozen', False): # required so iconfile can be packed by pyinstaller
application_path = sys._MEIPASS
elif __file__:
application_path = os.path.dirname(__file__)
iconfile = 'knob.png'
img = PhotoImage(file=os.path.join(application_path, iconfile))
The relevant docs: https://pyinstaller.readthedocs.io/en/latest/runtime-information.html#run-time-information
Doing a onedir build, I do not need to use the code above. Using relative paths for data works.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/60a7ae16.1c69fb81.c701c.e7faSMTPIN_ADDED_MISSING%40gmr-mx.google.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/60a7b160.1c69fb81.20f7d.97fcSMTPIN_ADDED_MISSING%40gmr-mx.google.com.