Skip to main content
 首页 » 编程设计

python之无法在docker中安装nmslib

2024年12月31日21qlqwjy

我无法在 docker 中使用 pip 安装 nmslib。

这是我的 Dockerfile:

FROM continuumio/anaconda3:4.4.0 
MAINTAINER UNP, https://unp.education 
EXPOSE 8000 
RUN apt-get update && apt-get install -y apache2 \ 
    apache2-dev \ 
    emacs \ 
 && apt-get clean \ 
 && apt-get autoremove \ 
 && rm -rf /var/lib/apt/lists/* 
WORKDIR /var/www/devise-api/ 
COPY ./devise-api.wsgi /var/www/devise-api/devise-api.wsgi 
COPY ./devise-api /var/www/devise-api/ 
RUN pip install -r requirements.txt 
RUN /opt/conda/bin/mod_wsgi-express install-module 
RUN mod_wsgi-express setup-server devise-api.wsgi --port=8000 \ 
    --user www-data --group www-data \ 
    --server-root=/etc/mod_wsgi-express-80 
CMD /etc/mod_wsgi-express-80/apachectl start -D FOREGROUND 

现在 requirements.txt 只包含单词 nmslib

这是我在运行 sudo docker build -t devise-api 时得到的输出。:

Sending build context to Docker daemon  306.2MB 
Step 1/11 : FROM continuumio/anaconda3:4.4.0 
 ---> 795ad88c47ff 
Step 2/11 : MAINTAINER UNP, https://unp.education 
 ---> Using cache 
 ---> cd5b1f7e6188 
Step 3/11 : EXPOSE 8000 
 ---> Using cache 
 ---> 21ad868f0823 
Step 4/11 : RUN apt-get update && apt-get install -y apache2     apache2-dev     emacs  && apt-get clean  && apt-get autoremove  && rm -rf /var/lib/apt/lists/* 
 ---> Using cache 
 ---> ebfc7c30b394 
Step 5/11 : WORKDIR /var/www/devise-api/ 
 ---> Using cache 
 ---> 8228e4b4d4fd 
Step 6/11 : COPY ./devise-api.wsgi /var/www/devise-api/devise-api.wsgi 
 ---> Using cache 
 ---> c8cf5cfcf7dc 
Step 7/11 : COPY ./devise-api /var/www/devise-api/ 
 ---> Using cache 
 ---> 856e67f0b1de 
Step 8/11 : RUN pip install -r requirements.txt 
 ---> Running in 7260901af476 
Collecting nmslib (from -r requirements.txt (line 1)) 
  Downloading https://files.pythonhosted.org/packages/e1/95/1f7c90d682b79398c5ee3f9296be8d2640fa41de24226bcf5473c801ada6/nmslib-1.7.3.6.tar.gz (255kB) 
Collecting pybind11>=2.0 (from nmslib->-r requirements.txt (line 1)) 
  Downloading https://files.pythonhosted.org/packages/f2/7c/e71995e59e108799800cb0fce6c4b4927914d7eada0723dd20bae3b51786/pybind11-2.2.4-py2.py3-none-any.whl (145kB) 
Requirement already satisfied: numpy in /opt/conda/lib/python3.6/site-packages (from nmslib->-r requirements.txt (line 1)) 
Building wheels for collected packages: nmslib 
  Running setup.py bdist_wheel for nmslib: started 
  Running setup.py bdist_wheel for nmslib: finished with status 'error' 
  Complete output from command /opt/conda/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-4qfop8hr/nmslib/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/tmpl9tnakclpip-wheel- --python-tag cp36: 
  running bdist_wheel 
  running build 
  running build_ext 
  creating tmp 
  gcc -pthread -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/opt/conda/include/python3.6m -c /tmp/tmp2pnwck3x.cpp -o tmp/tmp2pnwck3x.o -std=c++14 
  cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++ 
  gcc -pthread -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/opt/conda/include/python3.6m -c /tmp/tmp5ktoxd0l.cpp -o tmp/tmp5ktoxd0l.o -fvisibility=hidden 
  cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++ 
  building 'nmslib' extension 
  creating build 
  creating build/temp.linux-x86_64-3.6 
  creating build/temp.linux-x86_64-3.6/nmslib 
  creating build/temp.linux-x86_64-3.6/nmslib/similarity_search 
  creating build/temp.linux-x86_64-3.6/nmslib/similarity_search/src 
  creating build/temp.linux-x86_64-3.6/nmslib/similarity_search/src/space 
  creating build/temp.linux-x86_64-3.6/nmslib/similarity_search/src/method 
  gcc -pthread -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I./nmslib/similarity_search/include -I/opt/conda/include/python3.6m -I/root/.local/include/python3.6m -I/opt/conda/lib/python3.6/site-packages/numpy/core/include -I/opt/conda/include/python3.6m -c nmslib.cc -o build/temp.linux-x86_64-3.6/nmslib.o -O3 -march=native -fopenmp -DVERSION_INFO="1.7.3.6" -std=c++14 -fvisibility=hidden 
  cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++ 
  nmslib.cc:16:31: fatal error: pybind11/pybind11.h: No such file or directory 
   #include <pybind11/pybind11.h> 
                                 ^ 
  compilation terminated. 
  error: command 'gcc' failed with exit status 1 
 
  ---------------------------------------- 
  Failed building wheel for nmslib 
  Running setup.py clean for nmslib 
Failed to build nmslib 
Installing collected packages: pybind11, nmslib 
  Running setup.py install for nmslib: started 

然后就一直这样了。 有谁知道我可以尝试解决这个问题吗?

非常感谢您!

最好的问候

F

请您参考如下方法:

我刚刚遇到了同样的问题,并通过在安装 nmslib 之前添加 RUN 步骤来修复它:

RUN pip install pip==9.0.3 pybind11 

参见:https://github.com/nmslib/nmslib/issues/307#issuecomment-384113900 .希望这对您的情况也有帮助:-)