1

I have my application folder with my main.py and a lib folder with some modules:

LeapMotionInterpreter --> DataExtractor.py 
                          lib              --> Leap.py

I've already looked at how to do this and they all say to use sys.path.insert or sys.path.append but nothing seems to work, python doesn't even seem to know there is a lib folder there even though printing the sys.path does show the new added path to lib.

Here is the code I have tried:

1.

import sys
sys.path.insert(0, 'C:/Users/winba/Desktop/TYP/LeapMotionInterpreter/lib')
print (sys.path)

outputs:

['C:/Users/winba/Desktop/TYP/LeapMotionInterpreter/lib', 'C:\\Users\\winba\\Desktop\\TYP\\LeapMotionInterpreter'
import sys
sys.path.append('C:/Users/winba/Desktop/TYP/LeapMotionInterpreter/lib')
print (sys.path)

This one just outputs the lib path at the end of the array, I have also tried writing the paths with single \ or double \ instead of / but all of these just give me a 'No module named 'Leap' error if I try to import it and doesn't even acknowledge the existence of the lib folder. Also, putting my module in the same file seems to work as python is able to find the Leap.py file instantly however this is going to be a fairly big project and I wanted to keep it neat using folders so any help would be appreciated. Thank you.

Win Barua
  • 131
  • 1
  • 1
  • 5

1 Answers1

0

If I'm understanding correctly, the directory you're targeting is a sub-directory of the current directory. You can add the file to the Python path at runtime by giving it it's relative path:

# DataExtractor.py
import sys
sys.path.insert(1, 'lib')

import Leap

This should solve the problem

Dušan Stokić
  • 161
  • 1
  • 2
  • 13