Contents

pip-compile error by pip version compatibility

Contents

I setup python environment by pyenv and installed pip-tools by pip like:

1
2
3
4
5
> pyenv install 3.9.2 3.9.7
> pyenv 3.9.2
> pip install pip-tools
> pyenv 3.9.7
> pip install pip-tools

problem

With tox.ini setting pip-compile like below, tox -e pip-compile command failed.

tox.ini

1
2
3
4
5
6
7
8
9
[testenv:pip-compile]
deps=
    pip-tools==3.7
whitelist_external=
    sed
    rm

commands=
    pip-compile setup.py requirements.testing.in -v -o requirements.testing.txt -i https://"pypip repository"

Run pip-compile over tox

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
> cd "project directory"
> pyenv local 3.9.7
> pip --version
pip 22.1.2 from "user directory"/.pyenv/versions/3.9.7/lib/python3.9/site-packages/pip (python 3.9)
> tox -e pip-compile

...
  File "project directory"/.tox/pip-compile/lib/python3.9/site-packages/piptools/_compat/pip_compat.py", line 24, in do_import
    return getattr(imported, package)
AttributeError: module 'pip._internal.index' has no attribute 'PackageFinder'
ERROR: InvocationError for command  "project directory"/.tox/pip-compile/bin/pip-compile setup.py requirements.testing.in -v -o requirements.testing.txt -i https://"pypip repository" (exited with code 1)
__________________________________________________ summary __________________________________________________
ERROR:   pip-compile: commands failed

solution

In my case, this is solved by downgrading python 3.9.2 and pip 20.2.3. While it’s said that upgrading pip solves this.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
> pyenv local 3.9.2
> python -m ensurepip --upgrade
> pip --version
pip 20.2.3 from "user directory"/.pyenv/versions/3.9.2/lib/python3.9/site-packages/pip (python 3.9)
> pip-compile --version
pip-compile, version 6.6.2

> tox -e pip-compile
...
  pip-compile: commands succeeded
  congratulations :)

There is a table about pip-tools, pip, and python version compatibility

Looking carefully, pip-tools support on minor version of python 3.9 is not explicitly explained.

In my case, pip-tools itself has not been successfully installed on python 3.9.7 environment while 3.9.2 worked.

pyenv 3.9.2

1
2
> pip-compile --version
pip-compile, version 6.6.2

pyenv 3.9.7

1
2
3
4
> pip-compile --version
  File "user directory"/.pyenv/versions/3.9.7/lib/python3.9/site-packages/piptools/repositories/pypi.py", line 23, in <module>
    from pip._internal.cli.progress_bars import BAR_TYPES
ImportError: cannot import name 'BAR_TYPES' from 'pip._internal.cli.progress_bars' ("user directory"/.pyenv/versions/3.9.7/lib/python3.9/site-packages/pip/_internal/cli/progress_bars.py)