Packaging error trying to run ROS tests from Tox
When I run tox
to run Python tests in my ROS package, I'm getting the error:
ERROR: invocation failed (exit code 1), logfile: ros_qr_tracker/.tox/log/tox-0.log
ERROR: actionid: tox
msg: packaging
cmdargs: ['/usr/bin/python3', local('ros_qr_tracker/setup.py'), 'sdist', '--formats=zip', '--dist-dir', local('ros_qr_tracker/.tox/dist')]
env: None
Traceback (most recent call last):
File "setup.py", line 5, in <module>
from catkin_pkg.python_setup import generate_distutils_setup
ImportError: No module named 'catkin_pkg'
ERROR: FAIL could not package project - v = InvocationError('/usr/bin/python3 ros_qr_tracker/setup.py sdist --formats=zip --dist-dir ros_qr_tracker/.tox/dist (see ros_qr_tracker/.tox/log/tox-0.log)', 1)
My package is for Python 2.7. Why is it trying to run with Python3?
My setup.py
looks like:
#!/usr/bin/env python
import os
from distutils.core import setup
from catkin_pkg.python_setup import generate_distutils_setup
CURRENT_DIR = os.path.abspath(os.path.dirname(__file__))
def get_reqs(*fns):
lst = []
for fn in fns:
for package in open(os.path.join(CURRENT_DIR, fn)).readlines():
package = package.strip()
if not package:
continue
lst.append(package.strip())
return lst
d = generate_distutils_setup(
version='0.1.0',
packages=['ros_qr_tracker'],
package_dir={'': 'src'},
install_requires=get_reqs('pip-requirements.txt'),
)
setup(**d)
and my tox.ini
looks like:
[tox]
envlist = py{27}
recreate = True
[testenv]
basepython =
py27: python2.7
deps =
-r{toxinidir}/pip-requirements.txt
-r{toxinidir}/pip-requirements-test.txt
commands = nosetests -vv
As some other answers have pointed out, I've ensured catkin-pkg is installed by running sudo apt-get install python-catkin-pkg
and dpkg -L python-catkin-pkg
confirms the package was installed into Python2.7's site-packages, so the issue here seems to be that catkin-pkg is using the wrong version of Python. Why is this?
catkin_pkg
is a Python module, so a passive artefact. It cannot "use" a version of Python.I would check to make sure that
tox
is using / targetting the right Python version.