5

I have started working on Leap Motion Controller and when trying to execute my code I get this error:

ImportError: No module named Leap

I have added the path to the required libraries

import sys 
sys.path.append("usr/lib/Leap:/path/to/lib/x86:/path/to/lib")
import thread, time
from Leap import CircleGesture, KeyTapGesture, ScreenTapGesture, SwipeGesture

What am I doing wrong?

I am working on a Linux platform: Ubuntu 13.10, 32-bit

Zanna
  • 205
  • 5
  • 13
shruti
  • 459
  • 6
  • 24
  • http://stackoverflow.com/questions/3992952/importerror-no-module-named-in-python Check this question/answer. Also https://github.com/openleap/PyLeapMouse/issues/16 – GLHF Jan 25 '15 at 05:39

2 Answers2

4

You can't append a colon separated path list like this, as Python's sys.path stores the path entries an a list, and not a colon separated list. Each folder needs to be appended separately. Also, usr/lib/Leap looks to be missing the leading slash.

Something like this should work:

sys.path.append("/usr/lib/Leap")
sys.path.append("/path/to/lib/x86")
sys.path.append("/path/to/lib")

Or this:

sys.path += ["/usr/lib/Leap", "/path/to/lib/x86", "/path/to/lib"]
Alexander O'Mara
  • 58,688
  • 18
  • 163
  • 171
0

sys.path is not a string, it's a list of strings. So append individual path strings to it, not one single pathsep-delimited string:

sys.path.append("/usr/lib/Leap")
sys.path.append("/path/to/lib/x86")
sys.path.append("/path/to/lib")

Alternatively you can extend the list by adding another list of strings—for example, the list you get by calling split on your string:

sys.path += "/usr/lib/Leap:/path/to/lib/x86:/path/to/lib".split( ":" )

But ideally you should check whether each string is already on the path before adding, otherwise the path will get indefinitely long and redundant with repeated calls. For example:

for p in "/usr/lib/Leap:/path/to/lib/x86:/path/to/lib".split( ":" ):
     if p not in sys.path: sys.path.append( p )
jez
  • 14,867
  • 5
  • 37
  • 64