构建python停靠文件时出现psutil错误

i5desfxk  于 2023-04-10  发布在  Python
关注(0)|答案(2)|浏览(225)

我为我的Python重项目使用Python图像在下面构建了dockerfile

FROM python:3.11-slim-buster

# Update and install system packages
RUN apt-get update -y && \
  apt-get install --no-install-recommends -y -q \
  git libpq-dev python-dev && \
  apt-get clean && \
  rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Copy the requirements.txt file
COPY requirements.txt .

# Install Python dependencies using pip
RUN python3.11 -m pip install --no-cache-dir --upgrade pip \
    && python3.11 -m pip install --no-cache-dir -r requirements.txt

EXPOSE 9700

WORKDIR /my_app

requirements.txt包含

snowflake-connector-python==3.0.2
DataProflier==0.8.8

当我运行这个Dockerfile时,我得到错误:

note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for psutil
Failed to build psutil
ERROR: Could not build wheels for psutil, which is required to install 
pyproject.toml-based projects

根据其他帖子,我试图降低python镜像版本/ pip,但仍然得到相同的错误。我观察到,我只在安装requirements.txt中的某些包时得到此错误,如DataProfiler

编辑:

即使升级了安装工具,我仍然得到下面的错误

#0 10.85       error: command 'gcc' failed: No such file or directory
#0 10.85       [end of output]
#0 10.85   
#0 10.85   note: This error originates from a subprocess, and is likely not a problem with pip.
#0 10.85   ERROR: Failed building wheel for python-snappy
#0 10.85   Running setup.py clean for python-snappy
#0 11.06 Failed to build psutil python-snappy
#0 11.06 ERROR: Could not build wheels for psutil, which is required to install pyproject.toml-based projects
------
failed to solve: executor failed running [/bin/sh -c python3.11 -m pip install --no-cache-dir --upgrade pip && python3.11 -m pip install -U setuptools && python3.11 -m pip install --no-cache-dir -r requirements.txt]: exit code: 1
dl5txlt9

dl5txlt91#

升级setuptools为我解决了这个问题。

RUN python3.11 -m pip install --no-cache-dir --upgrade pip \
&& python3.11 -m pip install -U setuptools \
&& python3.11 -m pip install --no-cache-dir -r requirements.txt
oewdyzsn

oewdyzsn2#

通过更新系统包解决了上述问题,如下所示

RUN apt-get update -y && \
  apt-get install --no-install-recommends -y -q \
  git libpq-dev python-dev build-essential libsnappy-dev && \
  apt-get clean && \
  rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

相关问题