2017-04-01 62 views
1

我有下面的Dockerfile,我試圖用Python 3.6編譯Twisted作爲目標。在Alpine Linux for Python 3.6上編譯扭曲

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"] 

我的問題是,我發現了以下錯誤,扭曲已被複制後:

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 

這樣看來,東西扭曲指的是Python的2.7頭,我有沒有安裝,因爲我不打算針對該版本。

我無法找到針對Python 3.6的Twisted下載的特殊版本。

我屬於那些堅持2.7主要是因爲扭曲,我只是試圖讓我的腳溼3.6,所以請記住,當回答。我只是想檢查我的代碼是否在3.6上運行,我將不得不做出什麼樣的修改。但編譯Twisted是我的第一道屏障。

回答

2

您正在安裝的py-pip軟件包用於python 2.x.正因爲如此,當你打電話給pip install ...時,你正在爲python 2.x安裝軟件包。

python3軟件包提供了用於蟒3.在一般pip3命令,py-<something>是用於Python 2.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"]