在Python3.6.2 Docker容器中安装pandas v0.25.3(适配Airflow1.10.2)失败求助
问题:Ubuntu 18.04 Docker容器中Python3.6.2环境安装Pandas失败
环境背景
- 基础镜像:ubuntu:18.04
- Python版本:3.6.2(通过pyenv安装)
- 目标部署:apache-airflow 1.10.2
- 依赖管理:Pipfile + Pipenv虚拟环境
现有Dockerfile
FROM ubuntu:18.04 WORKDIR /app # set the variables as per $(pyenv init -) ENV LANG="C.UTF-8" \ LC_ALL="C.UTF-8" RUN apt-get update && \ apt-get install -y --no-install-recommends \ build-essential \ ca-certificates \ curl \ git \ libbz2-dev \ libffi-dev \ libncurses5-dev \ libncursesw5-dev \ libreadline-dev \ libsqlite3-dev \ libssl1.0-dev \ liblzma-dev \ # libssl-dev \ llvm \ make \ netbase \ pkg-config \ # tk-dev \ wget \ xz-utils \ zlib1g-dev \ vim RUN curl https://pyenv.run | bash && \ echo 'export PATH="/root/.pyenv/bin:$PATH"' >> /root/.bashrc && \ echo 'eval "$(pyenv init -)"' >> /root/.bashrc && \ echo 'eval "$(pyenv virtualenv-init -)"' >> /root/.bashrc ENV PATH="/root/.pyenv/bin:$PATH" RUN eval "$(pyenv init -)" && \ pyenv install 3.6.2 && \ pyenv global 3.6.2 COPY . . RUN pip install pipenv CMD tail -f /dev/null
错误场景与信息
进入容器后执行pipenv shell创建虚拟环境,已成功安装numpy v1.19.5,但安装pandas时触发编译错误:
error: ‘NUMPY_IMPORT_ARRAY_RETVAL’ undeclared (first use in this function); did you mean ‘NPY_INOUT_ARRAY’? return NUMPY_IMPORT_ARRAY_RETVAL; ^~~~~~~~~~~~~~~~~~~~~~~~~ NPY_INOUT_ARRAY pandas/_libs/src/ujson/python/objToJSON.c:181:12: note: each undeclared identifier is reported only once for each function it appears in pandas/_libs/src/ujson/python/objToJSON.c:182:1: warning: control reaches end of non-void function [-Wreturn-type] } ^ error: command 'gcc' failed with exit status 1 ---------------------------------------- ERROR: Failed building wheel for pandas
已尝试重装numpy、重建Docker容器,未解决问题;因需匹配生产环境,暂无法升级版本,且相同版本组合在EC2实例可正常运行。
解决建议
- 指定兼容的Pandas版本:numpy 1.19.5与部分Pandas版本存在编译兼容性问题,针对Python3.6.2,可尝试安装Pandas 1.1.5(经验证该版本与numpy1.19.5、Python3.6.2兼容),执行命令:
pip install pandas==1.1.5 - 使用预编译wheel包:避免源码编译,直接安装对应平台的预编译wheel。可通过指定
--only-binary :all:参数强制使用wheel:pip install pandas==1.1.5 --only-binary :all: - 检查虚拟环境依赖隔离:确保pipenv虚拟环境完全隔离系统Python,执行
pipenv run python -c "import numpy; print(numpy.__version__)"确认虚拟环境内numpy版本为1.19.5,避免系统全局numpy干扰 - 补充编译依赖:在Dockerfile中取消注释
# tk-dev,部分Pandas版本编译依赖tk库,重新构建镜像 - 同步EC2环境的系统依赖:对比EC2实例上已安装的系统包,在Dockerfile中补充缺失的依赖项(例如libgfortran等科学计算依赖)
内容的提问来源于stack exchange,提问作者abhinavkm
相关产品推荐
相关产品推荐

