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

How to change the version of Python catkin uses

asked 2016-01-08 12:49:08 -0600

Albatross gravatar image

I'm trying to create a package with catkin_create_pkg but it is failing with this error:

Traceback (most recent call last):
File "/usr/local/bin/catkin_create_pkg", line 10, in <module> from catkin_pkg.package_templates import create_package_files, PackageTemplate ImportError: No module named 'catkin_pkg'

I think this is because it is trying to use Python 3 rather than Python 2. (running python -c "import catkin_pkg" works, but running python3 -c "import catkin_pkg" gives the import error)

Is there a nice way to switch it to always use Python 2 instead (the default Python on my system, and the one I prefer to use)? I just installed it with apt-get following the tutorials. Other stuff like catkin_make and catkin_init_workspace work fine, catkin_create_pkg was the first command I ran into that didn't work.

edit retag flag offensive close merge delete

Comments

Which versions of Linux and ROS are you using? The version of catkin_create_pkg that you're calling is in /usr/local; how did you install it?

ahendrix gravatar image ahendrix  ( 2016-01-08 13:10:27 -0600 )edit

I'm using Ubuntu 14.04 with ROS Indigo. I think installed it with apt-get install python-catkin-pkg, I also did an install of ros-indigo-desktop-full earlier when going through the tutorials, which may have included it?

Albatross gravatar image Albatross  ( 2016-01-08 13:54:36 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted
2

answered 2016-01-08 17:07:51 -0600

ahendrix gravatar image

I've confirmed that catkin_create_pkg is included as part of the catkin_pkg python package (which you can install on Ubuntu through the python-catkin-pkg apt package). This means that if you have python-catkin-pkg installed, you should have catkin_create_pkg in /usr/bin

Since your version of catkin_create_pkg appears to be located in /usr/local/bin, I suspect you ALSO installed catkin_pkg though pip (or pip3) at some point. You should attempt to uninstall the version of catkin_pkg that was installed through pip:

pip uninstall catkin_pkg

(if you installed as root, you may need to run the unistall with sudo).

Note that this will not remove the version of catkin_pkg that was installed through apt (which is good)

edit flag offensive delete link more

Comments

Thanks! I've got it working now. Uninstalling with pip or pip3 didn't fix it (got a message saying it couldn't find anything to uninstall) so what I ended up doing was just renaming the file in /usr/local/bin to something else so it wouldn't use that one.

Albatross gravatar image Albatross  ( 2016-01-11 11:06:47 -0600 )edit

I checked the date on catkin_create_pkg from /usr/local, turns out it was created in 2013, so it must have been from when I was mucking around with ROS in the past. I thought I uninstalled all of the old stuff and replaced it with the new version, but it seems a few things were missed.

Albatross gravatar image Albatross  ( 2016-01-11 11:14:51 -0600 )edit

If you have old files installed by pip in /usr/local, and you're certain you don't need them any more, it's safe to delete them. (That's probably the case here). You may want to look through /usr/local/bin and /usr/local/lib/python2.7/dist-packages for any other old ROS packages and remove them too.

ahendrix gravatar image ahendrix  ( 2016-01-11 12:13:42 -0600 )edit
1

answered 2019-04-28 13:17:58 -0600

Fisherman gravatar image

If you use Anaconda3 for Python you have a PATH to python3 interpreter in your .bashrc file. You can change it to python2 (/usr/bin..) for example and your problem will solved.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-01-08 12:49:08 -0600

Seen: 10,351 times

Last updated: Jan 08 '16