Docker:如何运行cython_extensions?

时间:2015-08-04 10:22:01

标签: python docker cython

FROM ubuntu:14.04.2
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
RUN apt-get -y update && apt-get upgrade -y
RUN apt-get install python build-essential python-dev python-pip python-setuptools -y
RUN apt-get install libxml2-dev libxslt1-dev python-dev -y
RUN apt-get install libpq-dev postgresql-common postgresql-client -y
RUN apt-get install openssl openssl-blacklist openssl-blacklist-extra -y
RUN apt-get install nginx -y
RUN pip install "pip>=7.0"
RUN pip install virtualenv uwsgi

ADD canonicaliser_api /home/ubuntu/canonicaliser_api
RUN virtualenv /home/ubuntu/canonicaliser_api/venv
RUN source /home/ubuntu/canonicaliser_api/venv/bin/activate && pip install -r /home/ubuntu/canonicaliser_api/requirements.txt
RUN export CFLAGS=-I/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/core/include/
RUN source /home/ubuntu/canonicaliser_api/venv/bin/activate && \
    python /home/ubuntu/canonicaliser_api/canonicaliser/cython_extensions/setup.py \
      build_ext --inplace

最后一行崩溃:

  Traceback (most recent call last):
  File "/home/ubuntu/canonicaliser_api/canonicaliser/cython_extensions/setup.py", line 5, in <module>
    ext_modules = cythonize("*.pyx")
  File "/home/ubuntu/canonicaliser_api/venv/local/lib/python2.7/site-packages/Cython/Build/Dependencies.py", line 754, in cythonize
    aliases=aliases)
  File "/home/ubuntu/canonicaliser_api/venv/local/lib/python2.7/site-packages/Cython/Build/Dependencies.py", line 649, in create_extension_list
    for file in nonempty(extended_iglob(filepattern), "'%s' doesn't match any files" % filepattern):
  File "/home/ubuntu/canonicaliser_api/venv/local/lib/python2.7/site-packages/Cython/Build/Dependencies.py", line 103, in nonempty
    raise ValueError(error_msg)
ValueError: '*.pyx' doesn't match any files
...

我错过了什么?

1 个答案:

答案 0 :(得分:1)

我发现了问题。

  1. had to downgrade到Cython 0.21(这是主要原因 有问题的错误)

  2. 之后我又遇到了另一个问题,因为脚本没有生成 尽管没有丢失任何错误。解决方案是在执行它之前在该目录中。

  3. e.g:

    RUN source /home/ubuntu/canonicaliser_api/venv/bin/activate && cd /home/ubuntu/canonicaliser_api/canonicaliser/cython_extensions/ && python setup.py build_ext --inplace
    

    关于Docker的痛苦部分似乎是你必须链接所有的命令,因为它似乎是无状态的。