我对使用 docker 还不熟悉,目前需要帮助安装 PIL/pillow 以便在 docker 内部使用。这是我的 dockerfile
FROM nvidia/cuda:9.0-base-ubuntu16.04
# Install some basic utilities
RUN apt-get update && apt-get install -y \
curl \
ca-certificates \
sudo \
git \
bzip2 \
libx11-6 \
&& rm -rf /var/lib/apt/lists/*
# Create a working directory
RUN mkdir /app
WORKDIR /app
# Create a non-root user and switch to it
RUN adduser --disabled-password --gecos '' --shell /bin/bash user \
&& chown -R user:user /app
RUN echo "user ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/90-user
USER user
# All users can use /home/user as their home directory
ENV HOME=/home/user
RUN chmod 777 /home/user
# Install Miniconda
RUN curl -so ~/miniconda.sh https://repo.continuum.io/miniconda/Miniconda3-4.5.11-Linux-x86_64.sh \
&& chmod +x ~/miniconda.sh \
&& ~/miniconda.sh -b -p ~/miniconda \
&& rm ~/miniconda.sh
ENV PATH=/home/user/miniconda/bin:$PATH
ENV CONDA_AUTO_UPDATE_CONDA=false
# Create a Python 3.6 environment
RUN /home/user/miniconda/bin/conda install conda-build \
&& /home/user/miniconda/bin/conda create -y --name py36 python=3.6.5 \
&& /home/user/miniconda/bin/conda clean -ya
ENV CONDA_DEFAULT_ENV=py36
ENV CONDA_PREFIX=/home/user/miniconda/envs/$CONDA_DEFAULT_ENV
ENV PATH=$CONDA_PREFIX/bin:$PATH
# CUDA 9.0-specific steps
RUN conda install -y -c pytorch \
cuda90=1.0 \
magma-cuda90=2.4.0 \
"pytorch=1.0.0=py3.6_cuda9.0.176_cudnn7.4.1_1" \
torchvision=0.2.1 \
&& conda clean -ya
# Install HDF5 Python bindings
RUN conda install -y h5py=2.8.0 \
&& conda clean -ya
RUN pip install h5py-cache==1.0
# Install Torchnet, a high-level framework for PyTorch
RUN pip install torchnet==0.0.4
# Install Requests, a Python library for making HTTP requests
RUN conda install -y requests=2.19.1 \
&& conda clean -ya
# Install Graphviz
RUN conda install -c anaconda graphviz \
&& conda clean -ya
# Install OpenCV3 Python bindings
RUN sudo apt-get update && sudo apt-get install -y --no-install-recommends \
libgtk2.0-0 \
libcanberra-gtk-module \
&& sudo rm -rf /var/lib/apt/lists/*
RUN conda install -y -c menpo opencv3=3.1.0 \
&& conda clean -ya
# Install Numpy
RUN conda install -y -c anaconda numpy \
&& conda clean -ya
# Install Nano
RUN sudo apt-get update && sudo apt-get install -y nano
#Copy data
RUN mkdir sfsnet
COPY /SfSNet/ /app/sfsnet/
#PIL
RUN pip install Pillow
# Set the default command to python3
#CMD ["python3"]
可以看出,dockerfile 应该已经安装了它,但是当我尝试运行包含以下内容的代码时
from PIL import Image
它总会返回
from PIL import Image, ImageOps, ImageEnhance, PILLOW_VERSION
ImportError: cannot import name 'PILLOW_VERSION'
我希望有人能告诉我如何解决这个问题
答案1
Ubuntu 16.04pip
适用于 Python v2,因此您pip install Pillow
为 Python v2 环境安装了 Pillow,而您似乎使用的是 Python v3。请使用命令pip3
。