"2to3: command not found" in venv in Bionic

Hi, so I have a .travis.yml that works in ubuntu trusty and xenial on travis, but when I use dist: bionic, like this:

language: python
dist: bionic
  - pip install -U pip wheel
  - pip install -U setuptools
  - pip install -r requirements.txt
  - "3.6"
  - make flake8
  - make    

I get this error, coming from one of the python packages I’m using.

  running 2to3 on build/lib/logilab/astng/brain
  pyenv: 2to3: command not found
  The `2to3' command exists in these Python versions:

Here’s the full build:

I’ve also tried adding the 2to3 package to the build env, like this:

      - 2to3

And getting the same error. Anyways, has anyone else run into this in travis with Ubuntu 18.04 / Bionic? How did you fix it?

This is a problem with virtualenv, it doesn’t redirect 2to3 (probably assuming that it’s too rarely used).

So calling 2to3 “falls through” to the pyenv shim that’s the next on PATH (pyenv does redirect 2to3). And on pyenv level, the default selected version is system (the distro-provided version) for which 2to3 is not installed, so the shim emulates “command not found” error.

Since Travis-installed Python versions are manageable with pyenv, you can switch 2to3 to your selected version of Python with pyenv's means (I used Get path to original python executable (not the virtualenv) - Stack Overflow to deduce the command):

pyenv local $(basename $(python -c 'import sys; print(sys.real_prefix)'))

I created an issue in virtualenv's bug tracker: https://github.com/pypa/virtualenv/issues/1399

But Travis’ Python archives are bundled with pre-created virtualenvs to save time, so even when they fix this, Travis staff will need to recreate the archives for the fix to apply.

Just noting, I’m using python 3’s venv module, not virtualenv. I forgot to mention this in the original post.

Your build log says otherwise.
(Yes, it might be a misnamed venv, I don’t really know how to check.)

In any case, pyenv: 2to3: command not found means that whatever flavor of virtual environment you are using does not override 2to3 and my workaround should work.

Virtualenv maintainers suggested a more convenient workaround:

As a workaround, you can use python -m lib2to3 inside your virtualenv, with equivalent functionality.

The cause is the logilab-astng setup.py, and that has now been replaced with astroid.

The last version of logilab-astng is 2013 https://pypi.org/project/logilab-astng/#files , so you are unlikely to get assistance from them.
Upgrading to astroid will be one solution, highly recommended anyway because logilab-astng is abandonware.

You can also create your own 3to2 script which invokes /path/to/a/real/python3 -m lib2to3 - and put it first in the PATH so it is used before any other 3to2 in your PATH.

1 Like