Ask Your Question
0

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 that_custom_module_file.py and also this has the class that_Class of class that_class() in the former workspace.

Of course, that_custom_module_file.py 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 that_custom_module_file.py 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
0

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

srujan gravatar image

run thepython in the directory where the python script that_custom_module_file.py is located

edit flag offensive delete link more

Comments

Thanks for your reply. I tried that already and it didn't bring the ImportError wrt that_custom_module_file.py. 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

Stats

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

Seen: 212 times

Last updated: Feb 18 '20