0

I am trying to call a function defined in file lidar_source_code.py from my main script py_lidar_depressions.py. There are numerous sources which explain how to do this such as this one, however When I attempt this the error ModuleNotFoundError: No module named 'lidar_source_code' is returned. I must say that I am not surprised at this error as at no point did I point to where the file is located even though relevant tutorials do not seem to suggest the need to. The code to import the file and all of the defined functions was as simple as the following.

from lidar_source_code import *

Is there something I am missing here. Am I correct that one must first define the path of the function containing file before importing it?

Thanks

Max Duso
  • 305
  • 1
  • 4
  • 15
  • No, the path of the import is relative to your current working directory, so if both of those files are in the same directory and the current working directory is the directory where both of those files are, you wouldn't be getting this error, you can check your cwd using `print(os.get_cwd())` (`import os` first obvs) – Matiiss Feb 10 '23 at 22:26
  • ahah ok that makes sense. however now i have tried `import os cwd = os.getcwd() os.chdir("C:\\Users\\maxduso.stu\\Desktop\\FCOR_599\\project_work\\harrys_idea")` and the same error persists even thought when I `print(cwd) I get the correct path – Max Duso Feb 10 '23 at 22:52
  • is that the same directory as where both of the scripts are located, do you change it before importing? – Matiiss Feb 10 '23 at 23:52
  • https://stackoverflow.com/questions/65453576/diference-between-os-getcwd-and-os-path-dirname-file – Tim Williams Feb 11 '23 at 00:17

0 Answers0