skelpter
skelpter

Reputation: 21

Pipenv throws and error when installing in docker

Pipenv throws and error when installing in docker

[python-deps 5/5] RUN PIPENV_VENV_IN_PROJECT=1 pipenv install --deploy:

#10 7.577 Creating a virtualenv for this project...                                                                                                           
#10 7.578 Pipfile: /Pipfile                                                                                                                                   
#10 7.894 Using /usr/local/bin/python3 (3.10.8) to create virtualenv...                                                                                       
#10 17.28 created virtual environment CPython3.10.8.final.0-64 in 5775ms                                                                                      
#10 17.28   creator Venv(dest=/.venv, clear=False, no_vcs_ignore=False, global=False, describe=CPython3Posix)
#10 17.28   seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/root/.local/share/virtualenv)
#10 17.28     added seed packages: pip==22.3, setuptools==65.5.0, wheel==0.37.1
#10 17.28   activators BashActivator,CShellActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator
#10 17.28 
Traceback (most recent call last):
#10 17.29   File "/usr/local/lib/python3.10/site-packages/pipenv/utils/spinner.py", line 18, in create_spinner
#10 17.29     yield sp
#10 17.29   File "/usr/local/lib/python3.10/site-packages/pipenv/core.py", line 1019, in do_create_virtualenv
#10 17.29     sp.green.ok(
#10 17.29   File "/usr/local/lib/python3.10/site-packages/pipenv/vendor/vistir/spin.py", line 264, in ok
#10 17.29     self._freeze(_text, err=err)
#10 17.29   File "/usr/local/lib/python3.10/site-packages/pipenv/vendor/vistir/spin.py", line 363, in _freeze
#10 17.29     last_frame = self._compose_out(text, mode="last")
#10 17.29   File "/usr/local/lib/python3.10/site-packages/pipenv/vendor/vistir/spin.py", line 386, in _compose_out
#10 17.29     if self._color_func is not None:
#10 17.29   File "/usr/local/lib/python3.10/site-packages/pipenv/vendor/vistir/spin.py", line 115, in __getattr__
#10 17.29     retval = super(DummySpinner, self).__getattribute__(k)
#10 17.29 AttributeError: 'VistirSpinner' object has no attribute '_color_func'
#10 17.29 
#10 17.29 Traceback (most recent call last):
#10 17.29   File "/usr/local/bin/pipenv", line 8, in <module>
#10 17.30     sys.exit(cli())
#10 17.30   File "/usr/local/lib/python3.10/site-packages/pipenv/vendor/click/core.py", line 1128, in __call__
#10 17.30     return self.main(*args, **kwargs)
#10 17.30   File "/usr/local/lib/python3.10/site-packages/pipenv/cli/options.py", line 57, in main
#10 17.30     return super().main(*args, **kwargs, windows_expand_args=False)
#10 17.30   File "/usr/local/lib/python3.10/site-packages/pipenv/vendor/click/core.py", line 1053, in main
#10 17.30     rv = self.invoke(ctx)
#10 17.30   File "/usr/local/lib/python3.10/site-packages/pipenv/vendor/click/core.py", line 1659, in invoke
#10 17.30     return _process_result(sub_ctx.command.invoke(sub_ctx))
#10 17.30   File "/usr/local/lib/python3.10/site-packages/pipenv/vendor/click/core.py", line 1395, in invoke
#10 17.30     return ctx.invoke(self.callback, **ctx.params)
#10 17.31   File "/usr/local/lib/python3.10/site-packages/pipenv/vendor/click/core.py", line 754, in invoke
#10 17.31     return __callback(*args, **kwargs)
#10 17.31   File "/usr/local/lib/python3.10/site-packages/pipenv/vendor/click/decorators.py", line 84, in new_func
#10 17.31     return ctx.invoke(f, obj, *args, **kwargs)
#10 17.31   File "/usr/local/lib/python3.10/site-packages/pipenv/vendor/click/core.py", line 754, in invoke
#10 17.31     return __callback(*args, **kwargs)
#10 17.31   File "/usr/local/lib/python3.10/site-packages/pipenv/cli/command.py", line 236, in install
#10 17.31     do_install(
#10 17.31   File "/usr/local/lib/python3.10/site-packages/pipenv/core.py", line 2115, in do_install
#10 17.32     ensure_project(
#10 17.32   File "/usr/local/lib/python3.10/site-packages/pipenv/core.py", line 530, in ensure_project
#10 17.32     ensure_virtualenv(
#10 17.32   File "/usr/local/lib/python3.10/site-packages/pipenv/core.py", line 463, in ensure_virtualenv
#10 17.32     do_create_virtualenv(
#10 17.32   File "/usr/local/lib/python3.10/site-packages/pipenv/core.py", line 1019, in do_create_virtualenv
#10 17.32     sp.green.ok(
#10 17.32   File "/usr/local/lib/python3.10/site-packages/pipenv/vendor/vistir/spin.py", line 264, in ok
#10 17.32     self._freeze(_text, err=err)
#10 17.32   File "/usr/local/lib/python3.10/site-packages/pipenv/vendor/vistir/spin.py", line 363, in _freeze
#10 17.33     last_frame = self._compose_out(text, mode="last")
#10 17.33   File "/usr/local/lib/python3.10/site-packages/pipenv/vendor/vistir/spin.py", line 386, in _compose_out
#10 17.33     if self._color_func is not None:
#10 17.33   File "/usr/local/lib/python3.10/site-packages/pipenv/vendor/vistir/spin.py", line 115, in __getattr__
#10 17.33     retval = super(DummySpinner, self).__getattribute__(k)
#10 17.33 AttributeError: 'VistirSpinner' object has no attribute '_color_func'

executor failed running [/bin/sh -c PIPENV_VENV_IN_PROJECT=1 pipenv install --deploy]: exit code: 1

Dockerfile:

FROM python:3.10.8-buster as base

ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONFAULTHANDLER 1

FROM base AS python-deps

RUN pip install pipenv pytest

RUN apt-get update && apt-get install -y --no-install-recommends build-essential python-dev \
    libsasl2-dev libldap2-dev libbz2-dev libffi-dev default-libmysqlclient-dev libev4 libev-dev

COPY Pipfile .
COPY Pipfile.lock .

RUN PIPENV_VENV_IN_PROJECT=1 pipenv install --deploy

FROM base AS runtime

COPY --from=python-deps /.venv /.venv
ENV PATH="/.venv/bin:$PATH"

RUN useradd --create-home shopwalk
RUN mkdir -p /var/log/shopwalk/
RUN chown shopwalk /var/log/shopwalk/

WORKDIR /home/shopwalk
USER shopwalk

ENV PYTHONPATH="/home/shopwalk/app"

COPY . /home/shopwalk

CMD ["./start_server.sh"]

Pipfile:

[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"
 
[packages]
pipenv = "*"
uvicorn = "*"
fastapi = "*"
cassandra-driver = "*"
pydantic = "*"
starlette = "*"
 
[dev-packages]
pytest = "*"
 
[requires]
python_version = "3.10.8"

I am able to run it outside of docker properly. But docker build fails. docker build --platform=linux/amd64 -t shopwalk/location-api:latest .

Upvotes: 2

Views: 2866

Answers (1)

Frank2312
Frank2312

Reputation: 33

I encountered the same issue tonight. After looking around for a while (including finding this question at first), I tried an older version of pipenv than the one that was published ~5 hours ago and building my Docker image worked.

Until they publish a new version and fix the issue (it is being worked on : https://github.com/pypa/pipenv/pull/5460), you can force the pipenv version by replacing this line :

RUN pip install pipenv pytest

with this one, which installs the previous version of pipenv (https://pypi.org/project/pipenv/2022.10.25/) :

RUN pip install pipenv==2022.10.25 pytest

Upvotes: 3

Related Questions