tingbot / tide-electron

📝   Simple IDE for developing Tingbot apps
Other
22 stars 7 forks source link

OS X PNG/JPG dylib error #42

Closed Godzil closed 8 years ago

Godzil commented 8 years ago

Using the release version (0.0.2) when I try to use the screen.images function, it seems that the bundle pygame have an issue to find the library for PNG/JPG.

I'm using Mac OS X 10.12, so it maybe an incompatibilty with the beta, but I have a libpng.dylib and libjpeg.dylib from homebrew and they are working, but not to be found by Tide.

I don't know where tide expect to find this files as none are bundled into it. It maybe a good idea to bundle both of them as pygame seem to want them.

Godzil commented 8 years ago

More about what I found. I had a pygame installed in my system, looks to be the same version required by Tide, but I'm sure it wasn't conflicting. But there were a difference between the two:

When using otool -L to list shared lib dependencies, both the tide version and my version were referencing some libs like this:

Maya:pygame godzil$ otool -L imageext.so imageext.so: @loader_path/.dylibs/libSDL-1.2.0.dylib (compatibility version 12.0.0, current version 12.4.0) @loader_path/.dylibs/libSDL_image-1.2.0.dylib (compatibility version 9.0.0, current version 9.4.0) @loader_path/.dylibs/libpng16.16.dylib (compatibility version 40.0.0, current version 40.0.0) @loader_path/.dylibs/libjpeg.8.dylib (compatibility version 13.0.0, current version 13.0.0) /System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 20.0.0) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1)

They are configured to look at a folder named .dylibs that include some libraries. My local pygame installation had this folder, Tide one no. I copied the .dylibs folder to the Tide pygame folder ( ./Contents/Resources/vendor/tide-packages/pygame ) and I was finally able from command line python to import pygame, but, still not working when trying to load:

`` Python 2.7.10 (default, Aug 1 2016, 20:48:38) [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin Type "help", "copyright", "credits" or "license" for more information.

import pygame import io import requests r = requests.get("http://yaronet.org/193/layout/html/boo/china.png") r Response [200] img = io.BytesIO(r.content) surface = pygame.image.load(img) Traceback (most recent call last): File "", line 1, in pygame.error: Failed loading libpng.dylib: dlopen(libpng.dylib, 2): image not found `

I don't know where this libpng.dylib come from as none of the lib in pygame ask for that specific name..

joerick commented 8 years ago

Hi Godzil, thanks for the debugging so far 👍

I think we have two issues here - one is that somehow the packaged version of Tide hasn't included the .dylibs folder, the other is that the latest pygame wheels don't link against libpng quite right (see https://bitbucket.org/pygame/pygame/issues/300/os-x-wheels-dmg-and-zip-builds-with-travis).

Godzil commented 8 years ago

Ok, Ouch.. pygame seems to be a broken in some way on Mac OS X :(

As for the ilnks qnd comments there I will look at the SDL_Image imports to see if something wrong there and if it can be solved easily.

joerick commented 8 years ago

Hi Godzil

Could you try this build please? I've bundled a different version of pygame.

https://s3.amazonaws.com/tingbot-builds/tingbot/tide-electron/46/46.2/dist/mac/tide-electron-0.0.2-mac.zip

PNGs are working for me, but I'm seeing a weird JPEG bug on this build, let me know if this happens to you on 10.12.

Godzil commented 8 years ago

I will test later in the evening :)

joerick commented 8 years ago

This build includes a fix for the JPEG issue too :)

https://s3.amazonaws.com/tingbot-builds/tingbot/tide-electron/47/47.2/dist/mac/Tide-0.0.2-mac.zip

Godzil commented 8 years ago

Hum :-( The .so now look for .dylib file in /usr/local/lib and no longer in the .dylibs folder (which is still not there by the way, I don't know if this is normal)

Something strange, if I change the pygame .so files to use the .dylibs for the pygame installed on my computer I get the same error as before. If I leave the link to /usr/local/lib I get a error because I don't have a libSDL-1.2.0 & libSDL_ttf-2.0.0 here so if I redirect libSDL to the one I have in the .dylibs folder I get a weireder error with the same python code as earlier:

 File "/Applications/Tide.app/Contents/Resources/vendor/tide-packages/tingbot/graphics.py", line 410, in load_file           
    surface = pygame.image.load(file_object)                                                                                  
error: File is not a Windows BMP file

BTW I'm attaching the bash script I made to switch the libs to the local .dylibs folder in case you are insterested

updatelibs.sh.txt (renamed as txt because github don't want to attach a .sh file..)

Ok for the "BMP" I think I may understand. SDL_image is not found, so it's possible that pygame see that this lib is missing so it only try to load BMPs. It I switch the link path for SDL_image to the one in dylib, that where things fail.

It seems that the problem come from SDL_image that try to load manually the libjpeg/png/tiff dylib and probably in a way that does not respect how to search for libs. (otool does not answer any dependencies to libpng, but a "libpng.dylib" string is found in the binary, so, SDL_image try to open by hand the dylib using dlopen.

I'm trying to do a link to libpng16.16 to see in the .dylibs folder..

Godzil commented 8 years ago

I managed to get it to work! \o/

Ok thats not for production at all, ant clearly NOT a solution.. I've created a symlink to the libpng16.16.dylib file into.. the current working folder, so in my case:

/private/var/folders/n4/jjj0twtn557fz13f_n61hj700000gn/T/tide/53411ba6bf1d6daaf0605db0927d5cff/Tingstarter.tingapp/

And it worked 👍

capture d ecran 2016-08-30 a 20 49 03

Now, it's time to find a real solution for that stupid SDL_image.. :)

joerick commented 8 years ago

🙌 good job! Wow sorry that last build wasn't much better but good job getting it working. I'll keep at this pygame problem, I've an older build of pygame that might do the trick!

Godzil commented 8 years ago

No worries, it was fun :)

joerick commented 8 years ago

If you get a chance, could you test this build? https://s3.amazonaws.com/tingbot-builds/tingbot/tide-electron/48/48.2/dist/mac/Tide-0.0.2-mac.zip

Godzil commented 8 years ago

Sure! I'll edit this comment after downloading & testing

Edit: and result is.......

capture d ecran 2016-08-30 a 23 36 13

It works! 👍 👍 👍

joerick commented 8 years ago

Nice!! :D Thanks for the help.

joerick commented 8 years ago

By the way, I noticed you were doing a Kickstarter tracker app. I wrote one during our campaign that had a live display of the pledges - it uses a 'requests' session to grab a session cookie from the page so it can access a private API with live information.

# coding: utf8
import tingbot
from tingbot import *
import requests 

state = {}

@every(minutes=1)
def refresh():
    s = requests.Session()

    s.get('https://www.kickstarter.com/projects/744235676/tingbot-raspberry-pi-made-fun')

    r = s.get('https://www.kickstarter.com/projects/744235676/tingbot-raspberry-pi-made-fun/stats.json?v=1')
    r.raise_for_status()
    d = r.json()
    state['total'] = int(float(d['project']['pledged']))

def loop():
    screen.fill(color='green')
    screen.text(u'£' + str(state['total']), color='white')

# run the app
tingbot.run(loop)

Just thought it might be useful!

joerick commented 8 years ago

Just loaded a GIF in Tide and got this error again, this time failing to find PIL-bundled dylibs, presumably due to an incomplete copy by electron-builder/-packager.

dlopen(/Users/joerick/Work/Tingbot/9-tide-electron/dist/mac/Tide.app/Contents/Resources/vendor/ti
de-packages/PIL/_imaging.so, 2): Library not loaded: @loader_path/.dylibs/libjpeg.9.dylib        
  Referenced from: /Users/joerick/Work/Tingbot/9-tide-electron/dist/mac/Tide.app/Contents/Resourc
es/vendor/tide-packages/PIL/_imaging.so                                                          
  Reason: image not found                                                                        
Traceback (most recent call last):                                                               
  File "/Users/joerick/Work/Tingbot/15-tingbot-python/tingbot/run_loop.py", line 82, in run      
    next_timer.run()                                                                             
  File "/Users/joerick/Work/Tingbot/15-tingbot-python/tingbot/run_loop.py", line 17, in run      
    self.action()                                                                                
  File "/private/var/folders/st/_4b9_z_11gndqx5xz9hk4zjh0000gn/T/tide/90ab13486006379fc03c4c38fe3
a496c/Showing an image.tingapp/main.py", line 10, in loop                                        
    screen.image('giphy.gif')                                                                    
  File "/Users/joerick/Work/Tingbot/15-tingbot-python/tingbot/graphics.py", line 408, in image   
    super(Screen, self).image(*args, **kwargs)                                                   
  File "/Users/joerick/Work/Tingbot/15-tingbot-python/tingbot/graphics.py", line 310, in image   
    image = image_cache.get_image(image)                                                         
  File "/Users/joerick/Work/Tingbot/15-tingbot-python/tingbot/cache.py", line 144, in get_image  
    image = FileImage(location)                                                                  
  File "/Users/joerick/Work/Tingbot/15-tingbot-python/tingbot/cache.py", line 119, in __init__   
    self.image = graphics.Image.load_filename(filename)                                          
  File "/Users/joerick/Work/Tingbot/15-tingbot-python/tingbot/graphics.py", line 456, in load_fil
ename                                                                                            
    return cls.load_file(image_file, name_hint=filename)                                         
  File "/Users/joerick/Work/Tingbot/15-tingbot-python/tingbot/graphics.py", line 506, in load_fil
e                                                                                                
    return GIFImage(image_file=file_object)                                                      
  File "/Users/joerick/Work/Tingbot/15-tingbot-python/tingbot/graphics.py", line 590, in __init__
    from PIL import Image as PILImage                                                            
  File "/Users/joerick/Work/Tingbot/9-tide-electron/dist/mac/Tide.app/Contents/Resources/vendor/t
ide-packages/PIL/Image.py", line 67, in <module>                                                 
    from PIL import _imaging as core                                                             
ImportError: dlopen(/Users/joerick/Work/Tingbot/9-tide-electron/dist/mac/Tide.app/Contents/Resour
ces/vendor/tide-packages/PIL/_imaging.so, 2): Library not loaded: @loader_path/.dylibs/libjpeg.9.
dylib                                                                                            
  Referenced from: /Users/joerick/Work/Tingbot/9-tide-electron/dist/mac/Tide.app/Contents/Resourc
es/vendor/tide-packages/PIL/_imaging.so                                                          
  Reason: image not found  
Godzil commented 8 years ago

Thing would work easier with a Tingbot nearby.... ;)

joerick commented 8 years ago

We're working on it! 😅