Get the ros version installed using python code
Hello,
May I know which python package to used to find the ros version name and the detailed version number installed in my linux box.
TIA
Asked by sai krishna on 2019-10-16 15:25:14 UTC
Answers
I have found the version numbers just by looking at the ros_master's 'package.xml' and 'common.h' in the roscpp package.
That is exactly how rosversion -d
does it. See here:
mm = ManifestManager(PACKAGE_FILE)
path = mm.get_path(args.package)
package_manifest = os.path.join(path, 'package.xml')
if os.path.exists(package_manifest):
from xml.etree.ElementTree import ElementTree
try:
root = ElementTree(None, package_manifest)
version = root.findtext('version')
except Exception:
pass
Asked by gvdhoorn on 2019-10-17 02:30:09 UTC
Comments
an ugly way to grep the version name is to create a subprocess
pipe with the rosversion -d
(or rosversion pkg_name
for package version) command:
new_proc = subprocess.Popen(["rosversion", "-d"], stdout=subprocess.PIPE)
version_str = new_proc.communicate()[0]
Asked by pavel92 on 2019-10-17 03:12:46 UTC
Comments
Are you specifically restricted to python or is bash OK?
Asked by stevemacenski on 2019-10-16 16:14:31 UTC
And are you assuming you have sourced the setup file or not?
Asked by stevemacenski on 2019-10-16 16:15:15 UTC
yes i'm trying to understand only in python and I have sourced setup.bash file. I have found the version numbers just by looking at the ros_master's 'package.xml' and 'common.h' in the roscpp package. But I wanted to just use the information in my python application.
Asked by sai krishna on 2019-10-16 16:27:22 UTC
If you know what files theyre in, you can easily use python to crawl those files and extract the versions
Asked by stevemacenski on 2019-10-16 16:30:54 UTC