Cannot import a python file within the same directory.

asked 2020-12-14 06:24:58 -0500

Forenkazan gravatar image


I have two scripts: and I want to import in the to use some of the functions there. The files work perfectly when run normally:


However, when I call it using rosrun:

rosrun my_package

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:

#!/usr/bin/env python 

import test_lib

if __name__ == "__main__":

def test1():
edit retag flag offensive close merge delete


Both scripts are in the same folder (scripts). Here they are:

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 file to answer this one.

sloretz gravatar image sloretz  ( 2020-12-14 11:27:46 -0500 )edit

@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 since I assume they should work since they work normally in python using: python3

Forenkazan gravatar image Forenkazan  ( 2020-12-14 11:33:37 -0500 )edit