ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

I can't understand why this ImportError occurs

asked 2020-02-18 09:34:23 -0600

kane_choigo gravatar image

Hello, I'm using ROS kinetic on Ubuntu 16.04.

I know this issue would be the kind of pure Python, but I really don't know about this kind of error.

I'm working with openai_ros packages on the Python3 environment and I think I already have the necessary packages.

To use openai_ros packages, I have to activate a virtual Python3 environment in the specific workspace and let's assume that I have and also this has the class that_Class of class that_class() in the former workspace.

Of course, is not in the directory where python would be typed, but a deeper place.

I launched

$ python

and imported

$ from .that_custom_module_file import that_Class

but I got this error message:

SystemError: Parent module '' not loaded, cannot perform relative import

and when I typer

$ from that_custom_module_file import that_Class

I got another message:

ImportError: No module named 'that_custom_module_file'

why these errors occur?

Just so you know, openai_ros is ROS package and is just one of the python scripts.

I can

$ import rospy

$ from sensor_msgs,msg import LaserScan

which is not in the place where the command $python is launched.

what is the difference between these?

Just because of the PATH setting?

Then can I add the path of the virtual environment for Python3 into the real bashrc file?

Thanks in advance. :)

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2020-02-18 19:36:30 -0600

srujan gravatar image

run thepython in the directory where the python script is located

edit flag offensive delete link more


Thanks for your reply. I tried that already and it didn't bring the ImportError wrt Unfortunately, my source code includes other module files that are not in that directory, and it results in another ImportError. That is exactly why I got sad..

kane_choigo gravatar image kane_choigo  ( 2020-02-18 20:43:54 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2020-02-18 09:34:23 -0600

Seen: 546 times

Last updated: Feb 18 '20