ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

How do you change default python version in ros from 3.7 to 2.7 without re-installing everything?

asked 2020-01-28 04:06:35 -0600

isauma gravatar image

updated 2022-01-22 16:10:17 -0600

Evgeny gravatar image

I am getting an error message that looks likt this.

Traceback (most recent call last):
  File "/home/iskander/dd2419_ws/src/part2/scripts/navgoal2", line 5, in <module>
    from tf.transformations import euler_from_quaternion
  File "/opt/ros/melodic/lib/python2.7/dist-packages/tf/__init__.py", line 30, in <module>
    from tf2_ros import TransformException as Exception, ConnectivityException, LookupException, ExtrapolationException
  File "/opt/ros/melodic/lib/python2.7/dist-packages/tf2_ros/__init__.py", line 38, in <module>
    from tf2_py import *
  File "/opt/ros/melodic/lib/python2.7/dist-packages/tf2_py/__init__.py", line 38, in <module>
    from ._tf2 import *
ImportError: dynamic module does not define module export function (PyInit__tf2)

From my understanding, I can solve the problem by using python2.7 but ros run with default python3.7. How can I resolve this problem the easiest? I am trying to change the python default version in ros for this. The os I am using is ubuntu 18.04, I have ROS-melodic

edit retag flag offensive close merge delete

Comments

By default ROS 1 uses Python 2. What makes you think that it works with Python 3?

mbd gravatar image mbd  ( 2020-01-28 06:48:54 -0600 )edit

I literally wrote "From my understanding, I can solve the problem by using python2.7". I never said it works with python 3. I eventually solved the problems that I had so thanks anyway.

isauma gravatar image isauma  ( 2020-01-29 04:46:28 -0600 )edit

@isauma How did you solve this problem?

indraneel gravatar image indraneel  ( 2020-05-10 08:08:27 -0600 )edit
1

@indraneel, my problem was that I accidentally mixed installation between ROS kinetic and melodic creating problems plus that default was python3 instead of python2.7. I had to reinstall everything.

isauma gravatar image isauma  ( 2020-05-10 09:25:26 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2020-05-11 00:19:24 -0600

indraneel gravatar image

For anyone else who had this problem, reinstalling everything is not necessary, this should solve your problem :

  1. Ensure that which python returns /usr/bin/python
  2. Also ensure python --version returns Python 2.7.17
  3. Both the first and second point will most likely require you to make changes to your .bashrc, so once you do that source .bashrc
  4. export ROS_PYTHON_VERSION=2

Hope this helps!

edit flag offensive delete link more

Comments

my which python doesn't return /usr/bin/python, how do i change that?

ysl208 gravatar image ysl208  ( 2021-04-18 23:49:06 -0600 )edit

This worked for me:

sudo ln -sf /usr/bin/python2.7 /usr/bin/python

I got this answer here. You can read details in the actual answer page.

asaglam gravatar image asaglam  ( 2022-02-06 11:55:43 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2020-01-28 04:06:35 -0600

Seen: 9,609 times

Last updated: May 11 '20