Cannot import a python file within the same directory.
Hello
I have two scripts: caller.py and test_lib.py. I want to import test_lib.py in the caller.py to use some of the functions there. The files work perfectly when run normally:
python3 caller.py
However, when I call it using rosrun:
rosrun my_package caller.py
I get the following error
ModuleNotFoundError: No module named 'test_lib'
When I remove the import line, the program run without errors
Both scripts are in the same folder (scripts). Here they are:
caller.py
#!/usr/bin/env python
import test_lib
if __name__ == "__main__":
test_lib.test1()
test_lib.py
def test1():
print('test')
In the same folder in the source space? What folder are they in when they're installed? I think I would need to see the CMakeLists.txt and setup.py file to answer this one.
@sloretz yes they are in catkin_ws/src/PACKAGE/scripts. I did no edit the CMakeLists.txt, only added the two scripts to execute them using rosrun and did not create setup.py since I assume they should work since they work normally in python using: python3 caller.py
Hi @sloretz , @Forenkazan
Any solution to this? I am also facing the same issue.