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

python choice in some of ROS packages

asked 2013-12-07 05:20:00 -0500

Artem gravatar image

updated 2014-04-20 14:09:50 -0500

ngrennan gravatar image

I wonder why some .py files start with

#!/usr/bin/python

like in /camera_calibration/cameracalibrator.py while the others are with

#!/usr/bin/env python

like in /rosbag/bag2png.py

The choice could be critical if one have two copies of python, which is the case in Mac OSX. I have a default preinstalled python version (/usr/bin/python) and the other one is installed through homebrew (is in my PATH).

And a side question have somebody installed ros with a default python?

edit retag flag offensive close merge delete

3 Answers

Sort by » oldest newest most voted
6

answered 2013-12-08 09:13:25 -0500

I don't think there's a specific reason why some scripts use /usr/bin/python. For 99% of the users (on Ubuntu, for example) it doesn't make a difference, since they use the default python, so the script works for them either way. But you're right, the env version is more flexible, so my suggestion is whenever you run into a bug caused by this, write a bug report in the package's bug tracker.

edit flag offensive delete link more

Comments

I would add that if the script depends on python2.7, rather have `#!/usr/bin/env python2`. See answer by spease.

demmeln gravatar image demmeln  ( 2013-12-16 03:47:25 -0500 )edit
0

answered 2013-12-10 19:08:42 -0500

Artem gravatar image

updated 2013-12-16 01:59:32 -0500

I agree, it could be considered as a bug. I want to add a piece of advice for those who is on Mac OS X. Don't use homebrew python with ROS. With homebrew python I had errors that are hard to solve, such as this one Fatal Python error: PyThreadState_Get: no current thread main(). After switching to builtin python, the errors disappeared. Although I had to reinstall all python packages.

edit flag offensive delete link more
0

answered 2013-12-10 20:35:43 -0500

spease gravatar image

Another thing to consider is that certain distributions (eg Arch) default to the newest version of python when just using 'python'. However /usr/bin/env python2 seems to work on both Ubuntu and Arch and will enable a script to work even if it hasn't been ported.

Does the same hold true for OS X?

edit flag offensive delete link more

Comments

Sorry I didn't catch what you mean.

Artem gravatar image Artem  ( 2013-12-10 20:39:31 -0500 )edit

Specifying just 'python' makes scripts that only work with 2.7 or 3.3 distro-specific, because different distros have different default python versions. One fix is to use 'python2' or 'python3' to specify the right version. I don't have OS X to test if 'python2'/'python3' work the same there.

spease gravatar image spease  ( 2013-12-10 21:18:32 -0500 )edit

I am not 100% sure, but I believe all ROS packages are designed for python ver 2.7. I don't have python 3 installed, but as far as I know the executable for it is python3. So I don't think there will be ambiguity between versions.

Artem gravatar image Artem  ( 2013-12-10 23:42:54 -0500 )edit

`/usr/bin/env python2` works on my OS X system (Mavericks).

demmeln gravatar image demmeln  ( 2013-12-16 03:48:01 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2013-12-07 05:20:00 -0500

Seen: 776 times

Last updated: Dec 16 '13