Confused by module search paths

Jan 20, 2015 at 10:12 AM
Hi
I am quite new to Python and PTVS. I am running PTVS 2.1 on Win 8.1 and am trying to run a small module that uses Kivy. The import statements are:
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.factory import Factory
from kivy.properties import ObjectProperty
from kivy.uix.popup import Popup
When I ran this I got error:
ImportError: No module named 'kivy'
It seems to me that there may be two ways of solving this:

1) Set PYTHONPATH:

PYTHONPATH=C:\Kivy-1.8.0-py3.3-win32\kivy;

However, that didn't work for me.

I had set PYTHONPATH as a user environment variable but when I try to read it:
pythonpath = os.environ['PYTHONPATH']
print("pythonpath=",pythonpath)
it is not defined.

2) Set Properties > Debug > Search Path to:

C:\Kivy-1.8.0-py3.3-win32\Kivy

That did work but I then get a different error:

No module named 'Image'.

at line 10 of img_pil.py, which is:
import Image as PILImage
Please will you advise me which method I should use to specify the search path and why I don't see PYTHONPATH set?

If you have any hints about using PTVS with Kivy that would be a bonus.

Thanks in advance,

David
Coordinator
Jan 20, 2015 at 7:44 PM
The Search Path route is the one that you want to take. The reason why the import fails is because you don't have some of the dependencies that Kivy expects - in this case, PIL. Have a look at the list here:

http://kivy.org/docs/installation/installation.html
Coordinator
Jan 20, 2015 at 9:06 PM
See this page for an explanation of why we block the value of PYTHONPATH and how to use Search Paths through Solution Explorer.

There's also an option under Tools->Python Tools->General to allow global PYTHONPATH settings to be used within PTVS, but because of the potential issues this could cause, we don't recommend it.
Jan 25, 2015 at 8:26 PM
@DavidA2014 - Have you find out, how to resolve this issue. I have exactly the same problem.
Jan 27, 2015 at 11:15 AM
Which error message are you seeing?
Jan 29, 2015 at 12:57 PM
Hi

I think I have got to the bottom of this. To recap, I am trying to use PTVS to develop a Kivy application. Early errors were fixed by adding a search path to the PTVS project. However, I still got this error:
No module named 'Image'
due to:
try:
    from PIL import Image as PILImage
except:
    import Image as PILImage
in image_pil.py

pminaev wrote:
The Search Path route is the one that you want to take. The reason why the import fails is because you don't have some of the dependencies that Kivy expects - in this case, PIL. Have a look at the list here:

http://kivy.org/docs/installation/installation.html
I think that the standard Kivy installation does not provide package PILImage (which is as you suggested). The import is expected to fail and the 'except' clause substitutes the Image package for PILImage, so all is well. But PTVS detects the exception and stops execution. The fix is to disable 'Break when an exception is' in:

Debug > Exceptions > Python Exceptions > Python x.x > builtins > builtins.ImportError

Best regards

David