Ask Your Question
0

Python3 and python2 on package

asked 2020-05-18 15:29:17 -0500

czr gravatar image

Hi,

I have in my ROS package nodes that are supposed to be run with python2 and with python3. I wanto to maintain common code in shared libraries, a python2/3 lib and a python3 only lib. I read that I can keep my python packages on the /src folder and write a setup.py file so the packages would be installed and available to my nodes when a run catkin_make or catkin build.

The question is, how can I install both python3 and python2/3 packages in the same setup file? This could be done by catkin? If no, what would be the better way of organizing my code in this situation?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2020-06-01 17:28:47 -0500

Dirk Thomas gravatar image

When a package is being built it uses one specific Python interpreter. There is no option to perform two builds - one with Python 2 and one with Python 3.

A package can contain Python code though which works just fine with Python 2 as well as 3. Since the setup files extend the PYTHONPATH you can use the packages Python API with both Python versions afterwards.

For a whole ROS distribution the decision of the Python major version is being made for the packaging of binary packages. For ROS 1 Melodic and older Python 2 is being used. For ROS 1 Noetic Python 3 is being used.

Maybe you can describe your concrete use case in more detail for a specific feedback.

edit flag offensive delete link more

Comments

I saw some tutorials teaching to use Python3 with ROS melodic, but I realized that it is not worth it. My use case is that I wanted to use a model from Detectron2 (PyTorch) library but it only supports python 3, so I wanted to have two packages, one for python2/3 other python3 only. But I decided to use Mxnet/GluonCV instead since they still support python2.

czr gravatar image czr  ( 2020-06-03 18:06:57 -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: 2020-05-18 15:29:17 -0500

Seen: 49 times

Last updated: Jun 01