python:容器上的安装错误

2024-04-26 14:17:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在包含python的docker映像上安装pandas。我使用以下代码运行容器:


docker run -p 8888:8888 -v  /home/DATA/Project_NY/:/home/jovyan/work/Project_NY jupyter/scipy-notebook

我创建了一个新的笔记本,然后尝试安装我的需求文件执行pip install -r "requirements.txt"我得到了下面的错误,当我尝试pip install pandas在运行的容器中时,它工作得很好: requirements.txt内容

SQLAlchemy==1.2.2
pandas==0.25.0
docker==3.3.0
python-json-logger
sshtunnel==0.1.4
jupyter
jupytext==0.8.4
matplotlib
seaborn
psycopg2-binary

错误为

  building 'pandas._libs.algos' extension
  creating build/temp.linux-x86_64-3.9
  creating build/temp.linux-x86_64-3.9/pandas
  creating build/temp.linux-x86_64-3.9/pandas/_libs
  gcc -pthread -B /opt/conda/compiler_compat -Wno-unused-result -Wsign-compare -DNDEBUG -fwrapv -O2 -Wall -fPIC -O2 -isystem /opt/conda/include -fPIC -O2 -isystem /opt/conda/include -fPIC -DNPY_NO_DEPRECATED_API=0 -I./pandas/_libs -Ipandas/_libs/src/klib -Ipandas/_libs/src -I/opt/conda/lib/python3.9/site-packages/numpy/core/include -I/opt/conda/include/python3.9 -c pandas/_libs/algos.c -o build/temp.linux-x86_64-3.9/pandas/_libs/algos.o -Wno-unused-function
  error: command 'gcc' failed: No such file or directory
  ----------------------------------------
  ERROR: Failed building wheel for pandas


1条回答
网友
1楼 · 发布于 2024-04-26 14:17:09

您尝试安装的pandas版本似乎需要为您用作Dockercontainer的系统定制构建

如果在容器内运行pip install pandas==0.25.0,则会出现相同的错误

使用不同版本的pandas或在容器中安装gcc(例如:对于alpine,在DockerfileCMD apk add no-cache virtual .build-deps gcc内)

编辑:我认为“jupyter/scipy笔记本”图片使用了conda,所以不妨试试:

docker run -p 8888:8888 -v /home/DATA/Project_NY/:/home/jovyan/work/Project_NY jupyter/scipy-notebook conda install gcc

最后的conda install gcc在容器内执行

相关问题 更多 >