Trouble Importing A Python Module
I'm new to Python and having trouble importing from a different directory. The file I'm currently in has the path home/pi/example.py The module I'm trying to import into this file
Solution 1:
You need:
import piEngine
If your module is named piEngine.py
Furthermore, I recommend using absolute path for sys.path.append()
, assume that your module is in ~/home/pi/ReactiveEngine/src:
import os
sys.path.append(os.path.expanduser('~/home/pi/ReativeEngine/src'))
import piEngine
Solution 2:
Alternately:
import os
os.chdir('home/pi/ReactiveEngine/src')
import PiEngine
That should solve your problem!
Post a Comment for "Trouble Importing A Python Module"