Ask Your Question
0

Import error for rospy in Python3.6 script

asked 2020-03-24 09:46:02 -0500

mysqo gravatar image

updated 2020-03-24 10:11:40 -0500

I've tried import rospy into a python script that requires python3.6, but it gives me the error: ModuleNotFoundError: No module named 'rospy'

I'm able to successfully import the rospy into a python3.5 script.

So how can I install rospy package for python3.6 ?? When running in python 3.6 I first remove the path to the python2.7 link.

This works:

 dev@dev:~/tool_system$ python3.5
Python 3.5.2 (default, Oct  8 2019, 13:06:37) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import rospy
>>>

This does not work:

 dev@dev:~/tool_system$ python3.6
  Python 3.6.10 (default, Dec 19 2019, 23:04:32) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path.remove('/opt/ros/kinetic/lib/python2.7/dist-packages')
>>> import rospy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'rospy'
>>>
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2020-03-24 17:50:34 -0500

nkhedekar gravatar image

This worked for me:

sudo apt-get install python3-catkin-pkg-modules
sudo apt-get install python3-rospkg-modules

Refer: Gustavo's answer - https://answers.ros.org/question/2459...

edit flag offensive delete link more

Comments

Please note: this will only work for whatever the system default provided version of Python 3 is for the version of Debian/Ubuntu on which you run that apt command.

For Ubuntu Bionic, that would be 3.6.x I believe. Seeing as the OP shows two versions of Python which are different from that series, I assume he's installed those manually. The packages you mention will most likely not be available for those versions.

gvdhoorn gravatar image gvdhoorn  ( 2020-03-25 09:10:50 -0500 )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-03-24 09:46:02 -0500

Seen: 31 times

Last updated: Mar 24