Search code examples
dockerpython-3.7pipenv

Pip/pipenv not finding package inside Docker container?


I'm trying to use py-spy on my Python application who's development and deployment primarily happens in a Docker container, namely, python:3.7-alpine. When I run pip install py-spy locally in a virtualenv, it succeeds. Additionally, pypi has a listing for it.

Strangely, when I include it in my Pipfile, pipenv install is unable to find it in the Docker container and fails when trying to build. But it finds and installs the other Pipenv contents correctly.

The Dockerfile looks like this:

FROM python:3.7-alpine3.8
RUN mkdir -p /opt/app
WORKDIR /opt/app
RUN set -ex \
    && apk add libpq shadow \
    && apk add --no-cache --virtual .build-deps \
            gcc \
            git \
            bash \
            tmux \
            make \
            libcurl \
            curl-dev \
            libc-dev \
            musl-dev \
            linux-headers \
            pcre-dev \
            postgresql-dev \
            postgresql-libs \
            libffi-dev \
            ncurses-dev \
            python3-dev

RUN pip install pipenv
COPY Pipfile Pipfile.lock ./
RUN pipenv install --system --deploy --dev

# This is where we fail

Without py-spy, the whole thing builds. With py-spy = "*", running pipenv lock && docker-compose build, we get

An error occurred while installing py-spy==0.2.0.dev1 --hash=sha256:27f318826cb99a3cc4a089d8991e08ba8c86743ed9191799f39bc02cf1964a05 --hash=sha256:9e3d3f199c360dee58dbc9ce82e4dd9cb5ae3356466b25a8276bb972fdced2d9 --hash=sha256:c7c07b1557f372701ca3096582d487a19dd5ee7d0143c2c8dd3bdb0ec37c9450! Will try again.
Installing initially failed dependencies…
[pipenv.exceptions.InstallError]:   File "/usr/local/lib/python3.7/site-packages/pipenv/core.py", line 1874, in do_install
[pipenv.exceptions.InstallError]:       keep_outdated=keep_outdated
[pipenv.exceptions.InstallError]:   File "/usr/local/lib/python3.7/site-packages/pipenv/core.py", line 1253, in do_init
[pipenv.exceptions.InstallError]:       pypi_mirror=pypi_mirror,
[pipenv.exceptions.InstallError]:   File "/usr/local/lib/python3.7/site-packages/pipenv/core.py", line 859, in do_install_dependencies
[pipenv.exceptions.InstallError]:       retry_list, procs, failed_deps_queue, requirements_dir, **install_kwargs
[pipenv.exceptions.InstallError]:   File "/usr/local/lib/python3.7/site-packages/pipenv/core.py", line 763, in batch_install
[pipenv.exceptions.InstallError]:       _cleanup_procs(procs, not blocking, failed_deps_queue, retry=retry)
[pipenv.exceptions.InstallError]:   File "/usr/local/lib/python3.7/site-packages/pipenv/core.py", line 681, in _cleanup_procs
[pipenv.exceptions.InstallError]:       raise exceptions.InstallError(c.dep.name, extra=err_lines)
[pipenv.exceptions.InstallError]: ['Collecting py-spy==0.2.0.dev1 (from -r /tmp/pipenv-jxl1heir-requirements/pipenv-8_kalqyx-requirement.txt (line 1))']
[pipenv.exceptions.InstallError]: ['ERROR: Could not find a version that satisfies the requirement py-spy==0.2.0.dev1 (from -r /tmp/pipenv-jxl1heir-requirements/pipenv-8_kalqyx-requirement.txt (line 1)) (from versions: none)', 'ERROR: No matching distribution found for py-spy==0.2.0.dev1 (from -r /tmp/pipenv-jxl1heir-requirements/pipenv-8_kalqyx-requirement.txt (line 1))']
ERROR: ERROR: Package installation failed...

Does this ring any bells? py-spy has Rust dependencies, is there a way to check if its "invisible" to some architectures?


Solution

  • It was this:

    Alpine python opts out of the manylinux wheels: pypa/pip#3969 (comment). Before installing py-spy on Alpine docker containers do:

    echo 'manylinux1_compatible = True' > /usr/local/lib/python3.7/site-packages/_manylinux.py