无法安装scipy

jde*_*vio 3 python scipy docker

我正在尝试scipy从 a安装,但Dockerfile我一生都无法弄清楚如何安装。

这是Dockerfile

FROM python:3.5

ENV HOME /root

# Install dependencies
RUN apt-get update
RUN apt-get install -y gcc
RUN apt-get install -y build-essential
RUN apt-get install -y zlib1g-dev
RUN apt-get install -y wget
RUN apt-get install -y unzip
RUN apt-get install -y cmake
RUN apt-get install -y python3-dev
RUN apt-get install -y gfortran
RUN apt-get install -y python-numpy
RUN apt-get install -y python-matplotlib
RUN apt-get install -y ipython
RUN apt-get install -y ipython-notebook
RUN apt-get install -y python-pandas
RUN apt-get install -y python-sympy
RUN apt-get install -y python-nose

# Install Python packages
RUN pip install --upgrade pip
RUN pip install cython

# Install scipy
RUN apt-get install -y python-scipy
Run Code Online (Sandbox Code Playgroud)

这会构建一个图像,但是当我运行容器并尝试import scipy它时说:

Python 3.5.1 (default, Mar  9 2016, 03:30:07)
[GCC 4.9.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import scipy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'scipy'
Run Code Online (Sandbox Code Playgroud)

我试过使用RUN pip install scipyRUN pip install git+https://github.com/scipy/scipy.git但在完成构建之前会抛出错误。

Gar*_*yde 5

您使用的是 Python 3,但安装的是 Python 2 包。将您Dockerfile的更改为以下内容:

FROM python:3.5

ENV HOME /root
ENV PYTHONPATH "/usr/lib/python3/dist-packages:/usr/local/lib/python3.5/site-packages"

# Install dependencies
RUN apt-get update \
    && apt-get upgrade -y \
    && apt-get autoremove -y \
    && apt-get install -y \
        gcc \
        build-essential \
        zlib1g-dev \
        wget \
        unzip \
        cmake \
        python3-dev \
        gfortran \
        libblas-dev \
        liblapack-dev \
        libatlas-base-dev \
    && apt-get clean

# Install Python packages
RUN pip install --upgrade pip \
    && pip install \
        ipython[all] \
        numpy \
        nose \
        matplotlib \
        pandas \
        scipy \
        sympy \
        cython \
    && rm -fr /root/.cache
Run Code Online (Sandbox Code Playgroud)