1

tengo un problema cargando imagenes con el objeto AsyncImage me genera un error, cuando cargo imagenes desde la memoria interna no tengo problemas.

Mi código es_:

 #qpy:kivy
import kivy
kivy.require('1.10.0')
from kivy import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.image import Image, AsyncImage

layout = GridLayout(cols = 2)
picture = Image(source = "/sdcard/qpython/cat.jpg")
btn = Button ( text = "aceptar")
Pictureurl = AsyncImage(source = "https://commons.wikimedia.org/wiki/File:Firefox_Nightly_Logo,_2017.png")

layout.add_widget(picture)
layout.add_widget(btn )
layout.add_widget(Pictureurl)


class MainApp(App):
    def build(self):
        return layout
MainApp().Run()

El codigo funciona bien para las imagenes locales pero cuando intento extraer el recurso de internet me da un error en la libreria PIL raise AttributeError(name) AttributeError: tobytes

no carga la imagen y detiene la ejecuccion del script

Dato estoy usando estas configuraciones

[kivy ]v1.10.0
[python ]v2.7.12
[Image ] Providers: img_tex, img_dds, img_pygame, img_pil, img_gif
[Text ]Providers: pygame

Este es el codigo completo despues de arreglar la URL:

#qpy:kivy
import kivy
kivy.require('1.10.0')
from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.stacklayout import StackLayout
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
from kivy.network.urlrequest import UrlRequest
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.popup import Popup
from kivy.uix.textinput import TextInput
from kivy.lang import Builder
from kivy.properties import ObjectProperty, StringProperty
from kivy.clock import Clock
from kivy.uix.image import Image, AsyncImage
from kivy.uix.scatter import Scatter 
from kivy.loader import Loader 
import json
import urllib
import os
os.environ['KIVY_IMAGE'] = 'sdl2'
print(os.path.exists("/sdcard/qpython/cat.jpg"))


layout = GridLayout(cols = 2)
pictures = Image(source = "/sdcard/qpython/cat.jpg")
btn = Button(text = "Aceptar")
Pictureurl = AsyncImage(source = 'https://upload.wikimedia.org/wikipedia/commons/5/5c/Firefox_Nightly_Logo%2C_2017.png')
layout.add_widget(pictures)
layout.add_widget(btn)
layout.add_widget(Pictureurl)



class MainApp(App):
    def build(self):
        return layout

MainApp().run()

Este es el detalle completo del error (empieza creo después de la definición de los INFO de kivy)

[Device information]
RNE-L03,android:7.0,sdk:24 

[Recent error information]


[Or write your feedback here]: 
[INFO ] [Kivy ] v1.10.0
[INFO ] [Python ] v2.7.12 (default, Nov 21 2017, 21:49:35) 
[GCC 4.9.x 20150123 (prerelease)]
[INFO ] [Factory ] 194 symbols loaded
[INFO ] [Image ] Providers: img_tex, img_dds, img_pygame, img_pil, img_gif (img_ffpyplayer ignored)
[INFO ] [Text ] Provider: pygame
[INFO ] [Loader ] using a thread pool of 2 workers
True
[INFO ] [Window ] Provider: pygame
[INFO ] [GL ] Using the "OpenGL ES 2" graphics system
[INFO ] [GL ] Backend used <gl>
[INFO ] [GL ] OpenGL version <OpenGL ES 3.2 v1.r12p1-04bet0.b125fee3fb58301c951089b9a402d362>
[INFO ] [GL ] OpenGL vendor <ARM>
[INFO ] [GL ] OpenGL renderer <Mali-T830>
[INFO ] [GL ] OpenGL parsed version: 3, 2
[INFO ] [GL ] Texture max size <8192>
[INFO ] [GL ] Texture max units <16>
Traceback (most recent call last):
File "/data/user/0/org.qpython.qpy/files/lib/python27.zip/logging/__init__.py", line 882, in emit
stream.write(fs % msg)
File "<string>", line 23, in write
TypeError: argument 1 must be string without null bytes, not str
Logged from file __init__.py, line 1051
[ERROR ] [Shader ] GL error 1281
[INFO ] [Support ] Android install hooks
[INFO ] [Window ] virtual keyboard not allowed, single mode, not docked
[INFO ] [GL ] NPOT texture support is available
Traceback (most recent call last):
File "dirnameandimg.py", line 30, in <module>
Pictureurl = AsyncImage(source = 'https://upload.wikimedia.org/wikipedia/commons/5/5c/Firefox_Nightly_Logo%2C_2017.png';)
File "/data/user/0/org.qpython.qpy/files/lib/python2.7/site-packages/kivy_u4_qpython-1.10.0-py2.7.egg/kivy/uix/image.py", line 345, in __init__
self._load_source()
File "/data/user/0/org.qpython.qpy/files/lib/python2.7/site-packages/kivy_u4_qpython-1.10.0-py2.7.egg/kivy/uix/image.py", line 360, in _load_source
anim_delay=self.anim_delay)
File "/data/user/0/org.qpython.qpy/files/lib/python2.7/site-packages/kivy_u4_qpython-1.10.0-py2.7.egg/kivy/loader.py", line 448, in image
client = ProxyImage(self.loading_image,
File "/data/user/0/org.qpython.qpy/files/lib/python2.7/site-packages/kivy_u4_qpython-1.10.0-py2.7.egg/kivy/loader.py", line 168, in _get_loading_image
self._loading_image = ImageLoader.load(filename=loading_png_fn)
File "/data/user/0/org.qpython.qpy/files/lib/python2.7/site-packages/kivy_u4_qpython-1.10.0-py2.7.egg/kivy/core/image/__init__.py", line 435, in load
im = loader(filename, **kwargs)
File "/data/user/0/org.qpython.qpy/files/lib/python2.7/site-packages/kivy_u4_qpython-1.10.0-py2.7.egg/kivy/core/image/__init__.py", line 201, in __init__
self._data = self.load(filename)
File "/data/user/0/org.qpython.qpy/files/lib/python2.7/site-packages/kivy_u4_qpython-1.10.0-py2.7.egg/kivy/core/image/img_pil.py", line 101, in load
return list(self._img_read(im))
File "/data/user/0/org.qpython.qpy/files/lib/python2.7/site-packages/kivy_u4_qpython-1.10.0-py2.7.egg/kivy/core/image/img_pil.py", line 86, in _img_read
img_tmp.mode.lower(), img_tmp.tobytes())
File "/data/user/0/org.qpython.qpy/files/lib/python2.7/site-packages/PIL_u4_qpython-1.1.7-py2.7.egg/PIL/Image.py", line 512, in __getattr__
raise AttributeError(name)
AttributeError: tobytes

intente modificar el codigo para cargar una imagen con el elemento Loader pero obtengo el mismo error, posiblemente las librerias no funcionen, no llego a comprender el error.

#qpy:kivy
from kivy.app import App
from kivy.uix.image import Image
from kivy.loader import Loader
import PIL

class TestApp(App):
    def _image_loaded(self, proxyImage):
        if proxyImage.image.texture:
            self.image.texture = proxyImage.image.texture
    def build(self):
        proxyImage = Loader.image("https://upload.wikimedia.org/wikipedia/commons/d/d2/Firefox_Logo%2C_2017.png")
        proxyImage.bind(on_load=self._image_loaded)
        self.image = Image()
        return self.image
TestApp().run()

Detalle del Error:

[Feedback]: 

[Device information]
RNE-L03,android:7.0,sdk:24 

[Recent error information]


[Or write your feedback here]: 
[INFO ] [Kivy ] v1.10.0
[INFO ] [Python ] v2.7.12 (default, Nov 21 2017, 21:49:35) 
[GCC 4.9.x 20150123 (prerelease)]
[INFO ] [Factory ] 194 symbols loaded
[INFO ] [Image ] Providers: img_tex, img_dds, img_pygame, img_pil, img_gif (img_ffpyplayer ignored)
[INFO ] [Loader ] using a thread pool of 2 workers
Traceback (most recent call last):
File "loadertest.py", line 16, in <module>
TestApp().run()
File "/data/user/0/org.qpython.qpy/files/lib/python2.7/site-packages/kivy_u4_qpython-1.10.0-py2.7.egg/kivy/app.py", line 802, in run
root = self.build()
File "loadertest.py", line 12, in build
proxyImage = Loader.image("https://upload.wikimedia.org/wikipedia/commons/d/d2/Firefox_Logo%2C_2017.png";)
File "/data/user/0/org.qpython.qpy/files/lib/python2.7/site-packages/kivy_u4_qpython-1.10.0-py2.7.egg/kivy/loader.py", line 448, in image
client = ProxyImage(self.loading_image,
File "/data/user/0/org.qpython.qpy/files/lib/python2.7/site-packages/kivy_u4_qpython-1.10.0-py2.7.egg/kivy/loader.py", line 168, in _get_loading_image
self._loading_image = ImageLoader.load(filename=loading_png_fn)
File "/data/user/0/org.qpython.qpy/files/lib/python2.7/site-packages/kivy_u4_qpython-1.10.0-py2.7.egg/kivy/core/image/__init__.py", line 435, in load
im = loader(filename, **kwargs)
File "/data/user/0/org.qpython.qpy/files/lib/python2.7/site-packages/kivy_u4_qpython-1.10.0-py2.7.egg/kivy/core/image/__init__.py", line 201, in __init__
self._data = self.load(filename)
File "/data/user/0/org.qpython.qpy/files/lib/python2.7/site-packages/kivy_u4_qpython-1.10.0-py2.7.egg/kivy/core/image/img_pil.py", line 101, in load
return list(self._img_read(im))
File "/data/user/0/org.qpython.qpy/files/lib/python2.7/site-packages/kivy_u4_qpython-1.10.0-py2.7.egg/kivy/core/image/img_pil.py", line 86, in _img_read
img_tmp.mode.lower(), img_tmp.tobytes())
File "/data/user/0/org.qpython.qpy/files/lib/python2.7/site-packages/PIL_u4_qpython-1.1.7-py2.7.egg/PIL/Image.py", line 512, in __getattr__
raise AttributeError(name)
AttributeError: tobytes
4
  • No puedo probar nada en el móvil ahora, lo que si te puedo decir es que la url es incorrecta si no me equivoco, debería ser: source="https://upload.wikimedia.org/wikipedia/commons/5/5c/Firefox_Nightly_Logo%2C_2017.png". Con esto y corrigiendo los imports y lo de Run la imagen carga sin problemas usando sdl2 como backend (voy a ver si puedo testearlo con Pygame).
    – FJSevilla
    Commented el 3 may. 2018 a las 19:43
  • Gracias, intente modificar agregando la URL y cambiando sdl2 como backend pero sigue sin responder.
    – onerom
    Commented el 3 may. 2018 a las 21:56
  • Yo no puedo reproducirlo actualmente pero buscando me he encontrado con este bug, corregido en Noviembre del año pasado: github.com/kivy/kivy/issues/5460. Al parecer solo ocurría en Python 2, al usar PIL (no con el fork Pillow).
    – FJSevilla
    Commented el 3 may. 2018 a las 22:34
  • Muchas gracias, probablemente no sea posible, intentare correr una instancia de python 3 y ver si las librerías de kivy están disponibles dentro el emulador en android.
    – onerom
    Commented el 9 may. 2018 a las 14:17

0

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

Examina otras preguntas con la etiqueta o formula tu propia pregunta.