ImportError no module named common

Asked by manohar on 2020-09-15

my code looks like below

i have two file names called as test.py and common.py. test.py is in one folder and common.py is in another folder

test.py code:

import sys
sys.path.insert(1, '../lib')

import common

when i run in the editor then the error shows as ImportError no module named common.

please help me ASAP.

Question information

Language:
English Edit question
Status:
Solved
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
2020-09-16
Last query:
2020-09-16
Last reply:
2020-09-15
manohar (manohardama) said : #2

what version of SikuliX?
2.0.4
exact file/folder structure?
project
 -lib
    -common.py
 -test
     -test.py

i am running test.py file

Best RaiMan (raimund-hocke) said : #3

apparently the ../lib is not evaluated into an absolute path.

This should do the job:
libPath = os.path.join(getParentFolder(), "lib")
if not libPath in sys.path:
    sys.path.insert(1, libPath)

manohar (manohardama) said : #4

Thanks RaiMan, that solved my question.