Repository: kivy/kivy

Issue:
kivy error on Window8
This is the first time that I try to use kivy on my windows.So I download the file Kivy-1.8.0-py3.3-win32.zip and extracted it,but it can't run any codes even a very simple example.I don't think I  would like to test each program on my android phone...now I solved this problem through a strange way, , ,I think the kivy file must request some more files,but  am not sure how to find them.thanks to I had installed Python3.3 on my system.so I just combined the kivy folder with the Python folder directly.it is run.but I want to know why.maybe the kivy zip file also need package some more files.
please see the error file :
https://gist.github.com/MichaelJackson380/9735494



Discussion:
Hi,

Can you describe a bit more about how you're running kivy? You said you downloaded the zip file, but then you say you combined it with an already existing python3.3 you had on your system. The kivy zip files comes with python, and simply combining the code with an existing python isn't likely to work.

Regarding the original issues you had with the zip, what exactly was the issue? Did you run kivy using the kivy.bat file as described here? http://kivy.org/docs/installation/installation-windows.html

hey,sir.First I must say I am a beginner.not only for Python,also English.I just want to say some words about what happened to me.I donot know about the codes,I just copy my Python files to the kivy's directory Python33,but not overwrite when they are the same,so I think maybe there will be some more files required in kivy.I am sorry to bother you,sir.thank you for contacting with me.this is my first time to browse English Wdbs.so,please don't mind if I got something wrong.thank you

matham notifications@github.com wrote:

> Hi,
> 
> Can you describe a bit more about how you're running kivy? You said you
> downloaded the zip file, but then you say you combined it with an
> already existing python3.3 you had on your system. The kivy zip files
> comes with python, and simply combining the code with an existing
> python isn't likely to work.
> 
> Regarding the original issues you had with the zip, what exactly was
> the issue? Did you run kivy using the kivy.bat file as described here?
> http://kivy.org/docs/installation/installation-windows.html
> 
> ---
> 
> Reply to this email directly or view it on GitHub:
> https://github.com/kivy/kivy/issues/2015#issuecomment-38643730

## 

Sent from my Android device with Gmail Plus. Please excuse my brevity.

@MichaelJackson380 please rename your python folder (H:\资源\python) to something like 'H:\resources\python\', there may be a problem with accessing paths that contain unicode characters, like yours.

I think you're right.Thank you very much.But I also have some problems when
I try to package my kivy Demos to an apk.Could you please give me some more
advise?If so,I will send you the error log later.Thank you
On Apr 14, 2014 7:40 AM, "voen" notifications@github.com wrote:

> @MichaelJackson380 https://github.com/MichaelJackson380 please rename
> your python folder (H:\资源\python) to something like 'H:\dev\python\', there
> may be a problem with accessing paths that contain unicode characters, like
> yours.
> 
> —
> Reply to this email directly or view it on GitHubhttps://github.com/kivy/kivy/issues/2015#issuecomment-40323878
> .

@MichaelJackson380, to get further help with packaging problems, please visit https://webchat.freenode.net/?nick=MichaelJackson380&channels=kivy and ask there, someone will definitely find an answer to your problems.

Thank you
On Apr 14, 2014 11:56 PM, "voen" notifications@github.com wrote:

> @MichaelJackson380 https://github.com/MichaelJackson380, to get further
> help with packaging problems, please visit
> https://webchat.freenode.net/?nick=MichaelJackson380&channels=kivy and
> ask there, someone will definitely find an answer to your problems.
> 
> —
> Reply to this email directly or view it on GitHubhttps://github.com/kivy/kivy/issues/2015#issuecomment-40383393
> .


Resolving patch:
diff --git a/kivy/core/image/__init__.py b/kivy/core/image/__init__.py
--- a/kivy/core/image/__init__.py
+++ b/kivy/core/image/__init__.py
@@ -170,23 +170,26 @@ def save():
 
     def populate(self):
         self._textures = []
+        fname = self.filename
         if __debug__:
             Logger.trace('Image: %r, populate to textures (%d)' %
-                         (self.filename, len(self._data)))
+                         (fname, len(self._data)))
 
         for count in range(len(self._data)):
 
             # first, check if a texture with the same name already exist in the
             # cache
-            uid = '%s|%s|%s' % (self.filename, self._mipmap, count)
+            chr = type(fname)
+            uid = chr(u'%s|%d|%d') % (fname, self._mipmap, count)
             texture = Cache.get('kv.texture', uid)
 
             # if not create it and append to the cache
             if texture is None:
                 imagedata = self._data[count]
-                imagedata.source = '{}{}|{}'.format(
-                    'zip|' if self.filename.endswith('.zip') else '',
-                    self._nocache, uid)
+                source = '{}{}|'.format(
+                    'zip|' if fname.endswith('.zip') else '',
+                    self._nocache)
+                imagedata.source = chr(source) + uid
                 texture = Texture.create_from_data(
                     imagedata, mipmap=self._mipmap)
                 if not self._nocache:
@@ -331,7 +334,7 @@ def load(filename, **kwargs):
             if atlas:
                 texture = atlas[uid]
                 fn = 'atlas://%s/%s' % (rfn, uid)
-                cid = '%s|%s|%s' % (fn, False, 0)
+                cid = '{}|{:d}|{:d}'.format(fn, False, 0)
                 Cache.append('kv.texture', cid, texture)
                 return Image(texture)
 
@@ -347,7 +350,7 @@ def load(filename, **kwargs):
             # first time, fill our texture cache.
             for nid, texture in atlas.textures.items():
                 fn = 'atlas://%s/%s' % (rfn, nid)
-                cid = '%s|%s|%s' % (fn, False, 0)
+                cid = '{}|{:d}|{:d}'.format(fn, False, 0)
                 Cache.append('kv.texture', cid, texture)
             return Image(atlas[uid])
 
@@ -465,12 +468,14 @@ def remove_from_cache(self):
 
         '''
         count = 0
-        uid = '%s|%s|%s' % (self.filename, self._mipmap, count)
+        f = self.filename
+        pat = type(f)(u'%s|%d|%d')
+        uid = pat % (f, self._mipmap, count)
         Cache.remove("kv.image", uid)
         while Cache.get("kv.texture", uid):
             Cache.remove("kv.texture", uid)
             count += 1
-            uid = '%s|%s|%s' % (self.filename, self._mipmap, count)
+            uid = pat % (f, self._mipmap, count)
 
     def _anim(self, *largs):
         if not self._image:
@@ -601,7 +606,8 @@ def _set_filename(self, value):
         self._filename = value
 
         # construct uid as a key for Cache
-        uid = '%s|%s|%s' % (self.filename, self._mipmap, 0)
+        f = self.filename
+        uid = type(f)(u'%s|%d|%d') % (f, self._mipmap, 0)
 
         # in case of Image have been asked with keep_data
         # check the kv.image cache instead of texture.
@@ -633,7 +639,6 @@ def _set_filename(self, value):
             self._filename, keep_data=self._keep_data,
             mipmap=self._mipmap, nocache=self._nocache)
         self._filename = tmpfilename
-
         # put the image into the cache if needed
         if isinstance(image, Texture):
             self._texture = image
diff --git a/kivy/core/image/img_pygame.py b/kivy/core/image/img_pygame.py
--- a/kivy/core/image/img_pygame.py
+++ b/kivy/core/image/img_pygame.py
@@ -7,6 +7,7 @@
 from kivy.compat import PY2
 from kivy.logger import Logger
 from kivy.core.image import ImageLoaderBase, ImageData, ImageLoader
+from os.path import isfile
 
 try:
     import pygame
@@ -37,13 +38,23 @@ def can_save():
 
     def load(self, filename):
         try:
-            try:
+            im = None
+            if isfile(filename):
+                with open(filename, 'rb') as fd:
+                    im = pygame.image.load(fd)
+            elif isinstance(filename, bytes):
+                try:
+                    fname = filename.decode()
+                    if isfile(fname):
+                        with open(fname, 'rb') as fd:
+                            im = pygame.image.load(fd)
+                except UnicodeDecodeError:
+                    pass
+            if im is None:
                 im = pygame.image.load(filename)
-            except UnicodeEncodeError:
-                if PY2:
-                    im = pygame.image.load(filename.encode('utf8'))
         except:
-            Logger.warning('Image: Unable to load image <%s>' % filename)
+            Logger.warning(type(filename)('Image: Unable to load image <%s>')
+                           % filename)
             raise
 
         fmt = ''


Test patch: