Python Forum
No Module found in other directory than source code [SOLVED]
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
No Module found in other directory than source code [SOLVED]
#1
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?
Reply
#2
(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')
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  write code that resides in parent directory franklin97355 3 375 Apr-14-2024, 02:03 AM
Last Post: franklin97355
  delivery exe without source code py loky62 2 324 Apr-04-2024, 05:47 PM
Last Post: loky62
  Algorithm for extracting comments from Python source code Pavel1982 6 518 Feb-28-2024, 09:52 PM
Last Post: Pavel1982
  pyside6 module not found ForeverNoob 4 1,389 Aug-18-2023, 04:36 PM
Last Post: snippsat
  Error on import: SyntaxError: source code string cannot contain null bytes kirkwilliams2049 7 6,674 Aug-03-2023, 06:00 PM
Last Post: Gribouillis
  [SOLVED] [BeautifulSoup] Why attribute not found? Winfried 0 747 Mar-11-2023, 10:00 PM
Last Post: Winfried
  [SOLVED] [Windows] Right way to prompt for directory? Winfried 4 2,041 Jan-17-2023, 09:28 PM
Last Post: markoberk
  Module Not Found Error bitoded 4 1,405 Jan-01-2023, 09:08 AM
Last Post: bitoded
  [Solved]Help to iterate through code Extra 7 1,146 Dec-11-2022, 10:55 PM
Last Post: deanhystad
  How to run code again in module ? rajamani 2 896 Nov-10-2022, 02:38 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020