Ask Your Question
1

Importing a module that uses rospy from a module in Python3

asked 2017-06-16 03:11:32 -0500

hamzamerzic gravatar image

Hi. I have a library that is fully written in Python3.5 and I want to interface it with a module that I wrote. The module that I wrote imports rospy, so it depends on Python2.7. When I try to do this I get the following error:

python3 script_running_library_in_python3.py
Traceback (most recent call last):
  File "script_running_library_in_python3.py", line 11, in <module>
    from module_using_rospy.core import SomeClass
  File "/home/hamza/catkin_ws/src/module_using_rospy/module_using_rospy/core.py", line 9, in <module>
    import rospy
  File "/opt/ros/indigo/lib/python2.7/dist-packages/rospy/__init__.py", line 49, in <module>
    from .client import spin, myargv, init_node, \
  File "/opt/ros/indigo/lib/python2.7/dist-packages/rospy/client.py", line 47, in <module>
    import yaml
  File "/usr/local/lib/python2.7/dist-packages/yaml/__init__.py", line 2, in <module>
    from error import *
ImportError: No module named 'error'

Any idea how I could make this work? Thank you!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2017-07-31 11:31:19 -0500

hamzamerzic gravatar image

It was an error in how I sourced things and how I set up PYTHONPATH. The problem is the collision between libraries, and whichever one shows up first in the PYTHONPATH gets used, so it is important to make sure to have paths from the adequate python version first.

edit flag offensive delete link more

Comments

Are you able to write nodes in python 3 without any problems?

owerko gravatar image owerko  ( 2017-10-03 16:36:42 -0500 )edit

Yes, after fixing the PYTHONPATH it worked without issues. But keep in mind that some functionalities might not still be supported.

hamzamerzic gravatar image hamzamerzic  ( 2017-10-03 16:49:05 -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

2 followers

Stats

Asked: 2017-06-16 03:11:32 -0500

Seen: 1,005 times

Last updated: Jul 31 '17