Hi Mitchell,
I've only tried it briefly, but I think there may be some issues with the
pyglet.resource module when freezing using Pyinstaller. It does work,
however, if you just copy your /images folder alongside your executable.
By the way, it looks like you're using the resource module incorrectly. It
should be something like this:
# add a folder to the resource path
pyglet.resource.path.append("imgs")
pyglet.resource.reindex()
>From there, you can load any image in the "imgs" path without providing the
subdirectory. Like so:
pic = pyglet.resource.image("ad.jpg")
On Friday, December 16, 2016 at 8:09:31 AM UTC+9, Mitchell Barton wrote:
>
> Thanks for responding so quickly, sorry, I should have included the rest
> of my code in my first post. In the .spec file for pyinstaller I have tried
> including the images in a folder under 'added_files', that then is included
> under 'datas', but that could still be the problem. Here is what my code
> looks like for the .spec file, with 'beats' being a folder of .mp3 files
> and 'imgs' of jpgs -
>
> added_files = [
> ('beats', 'beats'),
> ('imgs', 'imgs')
> ]
>
> a = Analysis(['yep.py'],
> pathex = ['/Users/mitchellbarton/workspace/freestylez'],
> binaries = None,
> datas = added_files,
> )
>
>
> and then in my pyglet script -
>
> import os, sys, pyglet
> from random import shuffle
> from random import randint
> import subprocess
>
> # basic app info
>
> if getattr( sys, 'frozen', False ) :
> # running in a bundle
> print('bundle')
> else :
> # running live
> print('live')
>
> pyglet.options['audio'] = ('openal', 'silent')
> window = pyglet.window.Window(width=400, height=500)
> window.activate()
> window.set_caption('F R E E S T Y L E Z ( B A T T L E )')
> print('worked')
> pic1 = pyglet.resource.image('imgs/ad.jpg')
> pic2 = pyglet.resource.image('imgs/ad-2.jpg')
> pic3 = pyglet.resource.image('imgs/ad-3.jpg')
> pic4 = pyglet.resource.image('imgs/ad-4.jpg')
> pic5 = pyglet.resource.image('imgs/ad-5.jpg')
> picz = [pic1, pic2, pic3, pic4, pic5]
> shuffle(picz)
>
>
> I will also try your function to get the path of the image and see if it
> works.
>
> On Thu, Dec 15, 2016 at 3:52 PM <[email protected] <javascript:>> wrote:
>
>> Thats been a problem sometimes for myself as well, I've found it tricky
>> to get working at times. I'll try your approach next time I compile
>> something Chris, my own method involves using a small global function for
>> getting the absolute path when loading resources:
>> import sys
>> import os
>>
>> box = pyglet.image.load(resource_path('picture.png'))
>>
>> def resource_path(relative_path):
>> """ Get absolute path to resource, works for dev and for PyInstaller
>> """
>> if hasattr(sys, '_MEIPASS'):
>> return os.path.join(sys._MEIPASS, relative_path)
>>
>> return os.path.join(os.path.abspath("."), relative_path)
>>
>>
>> --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "pyglet-users" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/pyglet-users/q8diddF_uU8/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> [email protected] <javascript:>.
>> To post to this group, send email to [email protected]
>> <javascript:>.
>> Visit this group at https://groups.google.com/group/pyglet-users.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
--
You received this message because you are subscribed to the Google Groups
"pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.