Home > Net >  Cannot install many Python packages with one Docker RUN command
Cannot install many Python packages with one Docker RUN command

Time:10-30

I can install apt packages using one single Docker RUN command like:

RUN apt-get update && apt-get install -y --no-install-recommends \              
    gcc \                                                                   
    build-essential \                                                       
    zlib1g-dev \                                                            
    glade \                                                                 
    python3-dev \                                                           
    python3-pip \                                                           
    python3-setuptools \                                                    
    pkg-config \                                                            
    libglib2.0-dev \                                                        
    libgirepository1.0-dev \                                                
    libcairo2-dev \                                                         
    gir1.2-gtk-3.0 \ 

However I cannot do the same using Python pip within the Docker RUN command like:

RUN pip3 install \
    wheel \
    pycairo \
    PyGObject \
    requests \
    pyinstaller

Ending with error:

Collecting pyinstaller (from -r /tmp/requirements.txt (line 5))
  Downloading https://files.pythonhosted.org/packages/b0/e6/e5760666896739115b0e4538a42cdd895215581618ec885ad043dd35ee57/pyinstaller-4.10.tar.gz (2.7MB)
    Complete output from command python setup.py egg_info:
    Error: Building wheels requires the 'wheel' package. Please `pip install wheel` then try again.

Why?

Despite I can do this:

RUN pip3 install wheel                                                         
RUN pip3 install pycairo                                                       
RUN pip3 install PyGObject                                                     
RUN pip3 install requests                                                      
RUN pip3 install pyinstaller 

Still wish to understand why it cannot be done within ONE Docker RUN pip install command

CodePudding user response:

The problem with combined install

RUN pip3 install \
    wheel \
    pycairo \
    PyGObject \
    requests \
    pyinstaller

is that pip doesn't fully install packages until all listed packages are processed and there're packages that require wheel to be already fully installed. First install wheel separately, then everything else:

RUN pip3 install wheel
RUN pip3 install \
    pycairo \
    PyGObject \
    requests \
    pyinstaller

wheel is a special package — it's required to install other packages.

  • Related