在ARM64 docker容器中编译type-ast

时间:2019-03-19 08:22:11

标签: python docker pip

我正在multiarch ubuntu bionic ARM64 Docker容器中构建东西。我正在使用柯南进行依赖性管理。到目前为止,一切正常。

出于某种原因,我想从Python2.7柯南切换到Python3柯南。所以代替

ARG CONAN_VERSION=1.13.1
RUN apt-get update \
    && apt-get install -y --no-install-recommends \
    python-pip \
    && pip install wheel \
    && pip install "conan==$CONAN_VERSION" \
    && apt-get remove -y python-pip

我现在要做

ARG CONAN_VERSION=1.13.1
RUN apt-get update \
    && apt-get install -y --no-install-recommends \
    python3-pip \
    && pip3 install setuptools wheel \
    && pip3 install "conan==$CONAN_VERSION" \
    && apt-get remove -y python3-pip

但是这对我来说很困难

#12 132.3   Running setup.py install for typed-ast: started
#12 134.1     Running setup.py install for typed-ast: finished with status 'error'
#12 134.1     Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-hxn5kzw2/typed-ast/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-me7t6r8v-record/install-record.txt --single-version-externally-managed --compile:
#12 134.1     running install
#12 134.1     running build
#12 134.1     running build_py
#12 134.1     creating build
#12 134.1     creating build/lib.linux-aarch64-3.6
#12 134.1     creating build/lib.linux-aarch64-3.6/typed_ast
#12 134.1     copying typed_ast/ast3.py -> build/lib.linux-aarch64-3.6/typed_ast
#12 134.1     copying typed_ast/__init__.py -> build/lib.linux-aarch64-3.6/typed_ast
#12 134.1     copying typed_ast/ast27.py -> build/lib.linux-aarch64-3.6/typed_ast
#12 134.1     copying typed_ast/conversions.py -> build/lib.linux-aarch64-3.6/typed_ast
#12 134.1     running build_ext
#12 134.1     building '_ast27' extension
#12 134.1     creating build/temp.linux-aarch64-3.6
#12 134.1     creating build/temp.linux-aarch64-3.6/ast27
#12 134.1     creating build/temp.linux-aarch64-3.6/ast27/Parser
#12 134.1     creating build/temp.linux-aarch64-3.6/ast27/Python
#12 134.1     creating build/temp.linux-aarch64-3.6/ast27/Custom
#12 134.1     aarch64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -Iast27/Include -I/usr/include/python3.6m -c ast27/Parser/acceler.c -o build/temp.linux-aarch64-3.6/ast27/Parser/acceler.o
#12 134.1     unable to execute 'aarch64-linux-gnu-gcc': No such file or directory
#12 134.1     error: command 'aarch64-linux-gnu-gcc' failed with exit status 1

显然编译认为它需要交叉编译器?已安装gcc:

RUN apt-get update \
    && apt-get install -y --no-install-recommends \
    g++-5 gcc-5 make \
    python-dev python-setuptools \
    && rm -rf /var/lib/apt/lists/* \
    && update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 60 --slave /usr/bin/g++ g++ /usr/bin/g++-5

所以我真的不明白这里出了什么问题?

我尝试强制使用'gcc',但是没有用:

pip3 install --global-option build_ext --global-option --compiler=gcc "conan==$CONAN_VERSION"

#12 41.88     Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-vt3_j53z/typed-ast/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" build_ext --compiler=gcc install --record /tmp/pip-feshlu87-record/install-record.txt --single-version-externally-managed --compile:
#12 41.88     running build_ext
#12 41.88     error: don't know how to compile C/C++ code on platform 'posix' with 'gcc' compiler

1 个答案:

答案 0 :(得分:0)

我通过添加aarch64-linux-gnu-gcc的替代方案来解决我的问题

update-alternatives --install /usr/bin/$(gcc -dumpmachine)-gcc $(gcc -dumpmachine)-gcc /usr/bin/gcc 60 --slave /usr/bin/$(gcc -dumpmachine)-g++ $(gcc -dumpmachine)-g++ /usr/bin/g++