Python Forum

Full Version: No Module found in other directory than source code [SOLVED]
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

I have a question regarding a few python scripts I have. I cloned a few GitHub projects I did like to test on my Debian server.
When I execute an example script in the project folder it works but when I move the script to another directory and try to execute it there it says

File "/home/pi/example_script.py", line 1, in <module>
from x import X
ModuleNotFoundError: No module named 'x'

Do I have to link the script to the source code / project folder ? If yes, how do I do so?
(Nov-10-2021, 04:34 PM)AlphaInc Wrote: [ -> ]Hello,

I have a question regarding a few python scripts I have. I cloned a few GitHub projects I did like to test on my Debian server.
When I execute an example script in the project folder it works but when I move the script to another directory and try to execute it there it says

File "/home/pi/example_script.py", line 1, in <module>
from x import X
ModuleNotFoundError: No module named 'x'

Do I have to link the script to the source code / project folder ? If yes, how do I do so?

Sorry that was a dumb question, I figured it out myself:

import sys

#Import 
sys.path.insert(1, '/path/to/source/code')