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

ROS changed the Python Path

asked 2018-12-11 00:57:12 -0600

Jägermeister gravatar image

Hi, I've just installed ROS and I cannot use my Python 3.6 anymore. I did the following and saw:

os.getenv("PYTHONPATH")
'/home/user/ros_ws/devel/lib/python2.7/dist-packages:/opt/ros/melodic/lib/python2.7/dist-packages'

which shouldn't be the case. I don't know why ROS even screwed up my system paths like this, but this needs to change back to what it was since I don't use Python 2.7, not sure why ROS does either.

Does anyone know how I can get back my Python 3.6?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
3

answered 2018-12-11 01:02:48 -0600

gvdhoorn gravatar image

updated 2018-12-11 01:04:14 -0600

I don't know why ROS even screwed up my system paths like this, but this needs to change back

ROS did not "screwed up" your PYTHONPATH.

Python modules distributed as ROS packages are not installed in system locations, exactly to avoid "screw[ing] up" your Python setup. They are installed in /opt/ros/.

In order for Python to still be able to find those modules, the interpreter must somehow be made aware of them. So whenever you source /opt/ros/$ROS_DISTRO/setup.bash or your Catkin workspace's setup.bash (typically in the devel space), the PYTHONPATH variable gets updated to include the locations where ROS Python modules reside.

Without that change, nothing would work.

this needs to change back to what it was since I don't use Python 2.7, not sure why ROS does either.

The only Python version currently supported by ROS is 2.7, so it's expected to see python2.7 paths in PYTHONPATH. Please refer to REP-3: Target Platform: Melodic Morenia for the version of Python that is specced for Melodic.

As to why this is the case: please refer to earlier Q&As about ROS and Python 3.

Does anyone know how I can get back my Python 3.6?

It (most likely) never went anywhere: just make sure to not automatically source /home/user/ros_ws/devel/setup.bash if you do not need it and nothing should have changed.

If you want to make sure scripts and other programs use Python 3, spec python3 as the interpreter.

edit flag offensive delete link more

Comments

Finally: please refrain from using language such as "screwed up my X or Y". That implies someone deliberately tried to mess with your system for nefarious purposes almost. That is certainly not the case and using such language does not encourage people to try and help you.

gvdhoorn gravatar image gvdhoorn  ( 2018-12-11 01:05:46 -0600 )edit

Hmm well that's unfortunate, I guess I can't use ROS then, since I do everything in Python 3 and nothing in 2. How can I possibly revert this action now though? Should I modify my Pythonpath on my own? Like export PYTHONPATH=/usr/bin/python3 ?

Jägermeister gravatar image Jägermeister  ( 2018-12-11 01:31:19 -0600 )edit

I see two lines in my bashrc, source /opt/ros/melodic/setup.bash and source ~/ros_ws/devel/setup.bash, I should remove these in order to make Python3 work again, right?

Jägermeister gravatar image Jägermeister  ( 2018-12-11 01:33:32 -0600 )edit

Hmm well that's unfortunate, I guess I can't use ROS then, since I do everything in Python 3 and nothing in 2

As I wrote earlier: search for posts regarding ROS and Python 3 compatibility. There have been many, and it's certainly possible.

It's just not the default for now.

gvdhoorn gravatar image gvdhoorn  ( 2018-12-11 01:34:49 -0600 )edit

I see two lines in my bashrc, source /opt/ros/melodic/setup.bash and source ~/ros_ws/devel/setup.bash, I should remove these in order to make Python3 work again, right?

Removing / commenting those two lines will avoid updating PYTHONPATH, yes.

gvdhoorn gravatar image gvdhoorn  ( 2018-12-11 01:35:38 -0600 )edit

I did look up and saw comments like Anyway if you go that route you should expect problems and will find things which simply don't work with Python 3. so I am not willing to attempt this. But thanks.

Jägermeister gravatar image Jägermeister  ( 2018-12-11 01:36:41 -0600 )edit

The situation changes almost daily, so I would not necessarily be directly discouraged.

gvdhoorn gravatar image gvdhoorn  ( 2018-12-11 02:59:24 -0600 )edit

PYTHONPATH is used by the python interpreter to determine which modules to load.

PATH is used by the shell to determine which executables to run.

iangregor gravatar image iangregor  ( 2018-12-17 03:20:46 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-12-11 00:57:12 -0600

Seen: 5,714 times

Last updated: Dec 11 '18