2016-03-14 240 views
2

我正試圖從Dockerfile安裝scipy,我不能爲我的生活弄清楚如何。無法安裝scipy

這裏是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 

這將構建一個圖像,但是當我運行的容器,並嘗試import scipy它說:使用RUN pip install scipyRUN pip install git+https://github.com/scipy/scipy.git但這些

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' 

我曾嘗試在完成構建之前拋出一個錯誤。

+0

說實話,我並不熟悉碼頭工。什麼阻止你在終端上運行'pip install git + https:// github.com/scipy/scipy.git',除了'numpy'依賴? – Mai

+1

你不想要'python3-scipy'嗎?看起來你的系統默認使用Python3。 – Suever

+0

或者只是'運行pip安裝scipy'?雖然你可能想仔細檢查一下你使用的「pip」的確是Python 3.5點。 – Evert

回答

3

您正在使用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 
+0

我仍然得到'ImportError:沒有名爲'scipy''的模塊 – jdesilvio

+0

是的。 「PYTHONPATH」存在問題。即將更新。 –

+0

使用'apt-get install python3-numpy'時,numpy包內有一個bug。所以,我把所有的Python包都移到了'pip install'中。 –