Error – pip version 19.1.1, however version 20.2.4 is available – during Docker image creation

Question:

I created basic Dockerfile for my tiny app in Python.

FROM python:alpine3.8
COPY . /asfpApp
WORKDIR /asfpApp
RUN pip install -r requirements.txt
EXPOSE 5000
CMD python ./startApp.py

When I ran command

docker build  --tag name-of-app .

I got:

Collecting logging (from -r requirements.txt (line 1))
  Downloading https://files.pythonhosted.org/packages/93/4b/979db9e44be09f71e85c9c8cfc42f258adfb7d93ce01deed2788b2948919/logging-0.4.9.6.tar.gz (96kB)
    ERROR: Complete output from command python setup.py egg_info:
    ERROR: running egg_info
    creating pip-egg-info/logging.egg-info
    writing pip-egg-info/logging.egg-info/PKG-INFO
    writing dependency_links to pip-egg-info/logging.egg-info/dependency_links.txt
    writing top-level names to pip-egg-info/logging.egg-info/top_level.txt
    writing manifest file 'pip-egg-info/logging.egg-info/SOURCES.txt'
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-5jxduxvt/logging/setup.py", line 13, in <module>
        packages = ["logging"],
      File "/usr/local/lib/python3.7/distutils/core.py", line 148, in setup
        dist.run_commands()
      File "/usr/local/lib/python3.7/distutils/dist.py", line 966, in run_commands
        self.run_command(cmd)
      File "/usr/local/lib/python3.7/distutils/dist.py", line 985, in run_command
        cmd_obj.run()
      File "/usr/local/lib/python3.7/site-packages/setuptools/command/egg_info.py", line 296, in run
        self.find_sources()
      File "/usr/local/lib/python3.7/site-packages/setuptools/command/egg_info.py", line 303, in find_sources
        mm.run()
      File "/usr/local/lib/python3.7/site-packages/setuptools/command/egg_info.py", line 534, in run
        self.add_defaults()
      File "/usr/local/lib/python3.7/site-packages/setuptools/command/egg_info.py", line 570, in add_defaults
        sdist.add_defaults(self)
      File "/usr/local/lib/python3.7/distutils/command/sdist.py", line 226, in add_defaults
        self._add_defaults_python()
      File "/usr/local/lib/python3.7/site-packages/setuptools/command/sdist.py", line 127, in _add_defaults_python
        build_py = self.get_finalized_command('build_py')
      File "/usr/local/lib/python3.7/distutils/cmd.py", line 298, in get_finalized_command
        cmd_obj = self.distribution.get_command_obj(command, create)
      File "/usr/local/lib/python3.7/distutils/dist.py", line 857, in get_command_obj
        klass = self.get_command_class(command)
      File "/usr/local/lib/python3.7/site-packages/setuptools/dist.py", line 838, in get_command_class
        self.cmdclass[command] = cmdclass = ep.load()
      File "/usr/local/lib/python3.7/site-packages/pkg_resources/__init__.py", line 2434, in load
        return self.resolve()
      File "/usr/local/lib/python3.7/site-packages/pkg_resources/__init__.py", line 2440, in resolve
        module = __import__(self.module_name, fromlist=['__name__'], level=0)
      File "/usr/local/lib/python3.7/site-packages/setuptools/command/build_py.py", line 15, in <module>
        from setuptools.lib2to3_ex import Mixin2to3
      File "/usr/local/lib/python3.7/site-packages/setuptools/lib2to3_ex.py", line 12, in <module>
        from lib2to3.refactor import RefactoringTool, get_fixers_from_package
      File "/usr/local/lib/python3.7/lib2to3/refactor.py", line 18, in <module>
        import logging
      File "/tmp/pip-install-5jxduxvt/logging/logging/__init__.py", line 618
        raise NotImplementedError, 'emit must be implemented '
                                 ^
    SyntaxError: invalid syntax
    ----------------------------------------
ERROR: Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-5jxduxvt/logging/
WARNING: You are using pip version 19.1.1, however version 20.2.4 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
The command '/bin/sh -c pip install -r requirements.txt' returned a non-zero code: 1

Firstly I searched my issue, but I found only issue where two versions of pip is used. But that is not my case – as mentioned here Why is pip asking me to upgrade when it's already up-to-date? – I tried

pip show pip

and got:

Name: pip
Version: 20.2.4
Summary: The PyPA recommended tool for installing Python packages.
Home-page: https://pip.pypa.io/
Author: The pip developers
Author-email: [email protected]
License: MIT
Location: c:userspavelappdatalocalprogramspythonpython37-32libsite-packages
Requires:
Required-by:

then:

python -m pip show pip

and got

Name: pip
Version: 20.2.4
Summary: The PyPA recommended tool for installing Python packages.
Home-page: https://pip.pypa.io/
Author: The pip developers
Author-email: [email protected]
License: MIT
Location: c:userspavelappdatalocalprogramspythonpython37-32libsite-packages
Requires:
Required-by:

So I think I use correct version of pip. But when I went throught Docker Desktop and looked at unsuccessful build I found this command:

/bin/sh -c #(nop) ENV PYTHON_PIP_VERSION=19.1.1

So I guess that Docker thinks that I use old version eventhough in my machine is correct version. Any ideas what am I doing wrong?

Asked By: Pavel Petr

||

Answers:

In python3, there is already a build-in logging module, you no need to install it anymore, see this:

$ docker run --rm -it python:alpine3.8 python -c "import logging; print(logging.__file__)"
/usr/local/lib/python3.7/logging/__init__.py

As a result, the one you put in requirements.txt already deprecated for a long time, last released: Jun 5, 2013.

Answered By: atline
Categories: questions Tags: , , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.