作为 Docker 容器中的 Python 模块的 fasttext 构建错误

fasttext building error as Python module in Docker container

我一直在尝试在 docker 容器中安装 fasttext。在尝试多次预安装后,我遇到了同样的错误。

基本上,我在 windows 中有相同的代码,并且我在 PyCharm 中通过 pip 安装。它工作没有任何问题。我认为在基于 Linux 的系统中,它会更容易。但是,我还是无法解决安装问题。

这是错误片段:

gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall 
-fPIC -I/usr/local/lib/python3.7/site-packages/pybind11/include - 
I/usr/local/lib/python3.7/site-packages/pybind11/include -Isrc - 
I/usr/local/include/python3.7m -c 
python/fasttext_module/fasttext/pybind/fasttext_pybind.cc -o 
build/temp.linux-x86_64- 
3.7/python/fasttext_module/fasttext/pybind/fasttext_pybind.o - 
DVERSION_INFO="0.9.1" -std=c++14 -fvisibility=hidden
python/fasttext_module/fasttext/pybind/fasttext_pybind.cc: In lambda 
function:
python/fasttext_module/fasttext/pybind/fasttext_pybind.cc:296:35: warning: 
comparison of integer expressions of different signedness: ‘int32_t’ {aka 
‘int’} and ‘std::vector<long int>::size_type’ {aka ‘long unsigned int’} [- 
 Wsign-compare]
         for (int32_t i = 0; i < vocab_freq.size(); i++) {
                             ~~^~~~~~~~~~~~~~~~~~~
python/fasttext_module/fasttext/pybind/fasttext_pybind.cc: In lambda function:
python/fasttext_module/fasttext/pybind/fasttext_pybind.cc:310:35: warning: 
comparison of integer expressions of different signedness: ‘int32_t’ {aka ‘int’} and ‘std::vector<long int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
         for (int32_t i = 0; i < labels_freq.size(); i++) {
                             ~~^~~~~~~~~~~~~~~~~~~~
virtual memory exhausted: Cannot allocate memory
error: command 'gcc' failed with exit status 1
The command '/bin/sh -c cd fastText && python setup.py install' returned a non-zero code: 1

我的docker容器:

FROM python:3.7.4
WORKDIR /app
ADD . /app

# Install any necessary dependencies
RUN pip3 install --upgrade setuptools pip
RUN apt-get update && apt-get install
RUN apt install -y libprotobuf-dev protobuf-compiler
RUN python -m pip install --user numpy scipy
RUN apt-get install -y  software-properties-common
RUN add-apt-repository ppa:ubuntu-toolchain-r/test
RUN apt-get install -y build-essential -y gcc-7
RUN apt-get -y install make
RUN apt-get -qq -y install python3-dev
RUN pip3 install pybind11
RUN pip3 install --upgrade cython
RUN git clone https://github.com/facebookresearch/fastText.git
RUN cd fastText && python setup.py install
RUN pip3 install --trusted-host pypi.python.org -r requirements.txt

我错过了什么吗?预先要求指定为:

 fastText builds on modern Mac OS and Linux distributions. Since it uses C++11 features, it requires a 
 compiler with good C++11 support. You will need Python (version 2.7 or ≥ 3.4), NumPy & SciPy and 
 pybind11.

我已经尝试通过 pip3 安装 Numpy 和 sCipy,各种 gcc 版本,仅通过 pip install fasttext 等安装 fasttext。到目前为止没有任何效果。

有人可以帮忙解决这个错误吗?

阻塞错误如下:

virtual memory exhausted: Cannot allocate memory.

您的 RAM 内存不足以进行编译(参见 this)。

一个有用的建议是add a swap file