Reputation: 423
According to the readlink -f command in my terminal, the file that I'm currently in has the path /home/pi/example.py
The module I am trying to import into this file has the path /home/pi/ReactiveEngine/src/PiEngine.py
I have the following statements in my example.py file:
import os
os.chdir('/home/pi/ReactiveEngine/src/')
import PiEngine
But it's telling me that there's no module named PiEngine even though there clearly is. Am I doing something wrong or what could be giving me this error?
Upvotes: 0
Views: 62
Reputation: 1264
you can add to the Python path at runtime using sys.path.insert()
import sys
sys.path.insert(0, '/home/pi/ReactiveEngine/src')
import PiEngine
Upvotes: 0
Reputation: 7946
The variable sys.path
determines where files are imported from. So I think you're looking for something like:
import sys
sys.path.append('/home/pi/ReactiveEngine/src/')
import PiEngine
Upvotes: 2