在 Alpine Linux 上为 Python 3.6 编译 Twisted
Compiling Twisted on Alpine Linux for Python 3.6
我有以下 Dockerfile,我正在尝试以 Python 3.6 作为目标编译 Twisted。
FROM alpine:3.5
RUN apk --update add \
build-base libffi-dev openssl-dev python3-dev \
libffi openssl ca-certificates python3
RUN apk add \
py-pip \
py-lxml \
py-pillow
RUN \
pip install --upgrade python-dateutil \
arrow \
pytz \
zope.interface \
https://files.pythonhosted.org/packages/source/T/Twisted/Twisted-17.1.0.tar.bz2 \
jinja2
RUN \
apk del build-base libffi-dev openssl-dev python3-dev && \
rm -rf /var/cache/apk/* && \
rm -rf ~/.cache/ && \
adduser -D -u 1001 noroot
USER noroot
CMD ["/bin/sh"]
我的问题是在复制 Twisted 后出现以下错误:
gcc -fno-strict-aliasing -Os
-fomit-frame-pointer -g -DNDEBUG -Os -fomit-frame-pointer
-g -fPIC -I/usr/include/python2.7 -c src/twisted/test/raiser.c
-o build/temp.linux-x86_64-2.7/src/twisted/test/raiser.o
src/twisted/test/raiser.c:4:20: fatal error: Python.h: No such file or
directory
看来 Twisted 中的某些内容指的是 Python 2.7 headers,我还没有安装它,因为我不打算针对该版本。
我找不到针对 Python 3.6.
的 Twisted 下载的特殊版本
我属于那些坚持使用 2.7 的人,主要是因为 Twisted,我只是想尝试一下 3.6,所以在回答时请记住这一点。我只是想检查我的代码是否在 3.6 上运行,我必须进行哪些修改。但是编译Twisted是我的第一个障碍。
您正在安装的 py-pip
软件包适用于 python 2.x。因此,当您调用 pip install ...
时,您正在为 python 2.x.
安装软件包
python3
包为python3提供了pip3
命令。一般来说,py-<something>
是针对Python2.x,并且py3-<something>
用于 Python 3.x。换句话说:
FROM alpine:3.5
RUN apk --update add \
build-base libffi-dev openssl-dev python3-dev \
libffi openssl ca-certificates python3
RUN apk add \
py3-lxml \
py3-pillow
RUN \
pip3 install --upgrade python-dateutil \
arrow \
pytz \
zope.interface \
https://files.pythonhosted.org/packages/source/T/Twisted/Twisted-17.1.0.tar.bz2 \
jinja2
RUN \
apk del build-base libffi-dev openssl-dev python3-dev && \
rm -rf /var/cache/apk/* && \
rm -rf ~/.cache/ && \
adduser -D -u 1001 noroot
USER noroot
CMD ["/bin/sh"]
我有以下 Dockerfile,我正在尝试以 Python 3.6 作为目标编译 Twisted。
FROM alpine:3.5
RUN apk --update add \
build-base libffi-dev openssl-dev python3-dev \
libffi openssl ca-certificates python3
RUN apk add \
py-pip \
py-lxml \
py-pillow
RUN \
pip install --upgrade python-dateutil \
arrow \
pytz \
zope.interface \
https://files.pythonhosted.org/packages/source/T/Twisted/Twisted-17.1.0.tar.bz2 \
jinja2
RUN \
apk del build-base libffi-dev openssl-dev python3-dev && \
rm -rf /var/cache/apk/* && \
rm -rf ~/.cache/ && \
adduser -D -u 1001 noroot
USER noroot
CMD ["/bin/sh"]
我的问题是在复制 Twisted 后出现以下错误:
gcc -fno-strict-aliasing -Os
-fomit-frame-pointer -g -DNDEBUG -Os -fomit-frame-pointer
-g -fPIC -I/usr/include/python2.7 -c src/twisted/test/raiser.c
-o build/temp.linux-x86_64-2.7/src/twisted/test/raiser.o
src/twisted/test/raiser.c:4:20: fatal error: Python.h: No such file or
directory
看来 Twisted 中的某些内容指的是 Python 2.7 headers,我还没有安装它,因为我不打算针对该版本。
我找不到针对 Python 3.6.
的 Twisted 下载的特殊版本我属于那些坚持使用 2.7 的人,主要是因为 Twisted,我只是想尝试一下 3.6,所以在回答时请记住这一点。我只是想检查我的代码是否在 3.6 上运行,我必须进行哪些修改。但是编译Twisted是我的第一个障碍。
您正在安装的 py-pip
软件包适用于 python 2.x。因此,当您调用 pip install ...
时,您正在为 python 2.x.
python3
包为python3提供了pip3
命令。一般来说,py-<something>
是针对Python2.x,并且py3-<something>
用于 Python 3.x。换句话说:
FROM alpine:3.5
RUN apk --update add \
build-base libffi-dev openssl-dev python3-dev \
libffi openssl ca-certificates python3
RUN apk add \
py3-lxml \
py3-pillow
RUN \
pip3 install --upgrade python-dateutil \
arrow \
pytz \
zope.interface \
https://files.pythonhosted.org/packages/source/T/Twisted/Twisted-17.1.0.tar.bz2 \
jinja2
RUN \
apk del build-base libffi-dev openssl-dev python3-dev && \
rm -rf /var/cache/apk/* && \
rm -rf ~/.cache/ && \
adduser -D -u 1001 noroot
USER noroot
CMD ["/bin/sh"]