ImportError:无法导入在tensorflow上加载图像文件所需的Python Imaging Library(PIL)

时间:2022-12-24 00:23:21

I am doing a deep learning course on udacity. For the first assignment whenI tried to run the script which is below the problem 1 , I got this error. So I tried to uninstall PIL and pillow and then installed these individually but I didnot succeeded. I need help guy. I am using tensorflow docker image with python notebook.

我正在做一个关于udacity的深入学习课程。对于第一次分配,当我试图运行低于问题1的脚本时,我收到了这个错误。所以我试图卸载PIL和枕头,然后单独安装,但我没有成功。我需要帮助的人。我用python笔记本使用tensorflow docker图像。

# These are all the modules we'll be using later. Make sure you can import them
# before proceeding further.
from __future__ import print_function
import matplotlib.pyplot as plt
import numpy as np
import os
import sys
import scipy
import tarfile
from IPython.display import display, Image
from scipy import ndimage
from sklearn.linear_model import LogisticRegression
from six.moves.urllib.request import urlretrieve
from six.moves import cPickle as pickle
# Config the matplotlib backend as plotting inline in IPython
%matplotlib inline 

url = 'http://commondatastorage.googleapis.com/books1000/'
last_percent_reported = None

def download_progress_hook(count, blockSize, totalSize):
    percent = int(count * blockSize * 100 / totalSize)

   if last_percent_reported != percent:
     if percent % 5 == 0:
  sys.stdout.write("%s%%" % percent)
  sys.stdout.flush()
else:
  sys.stdout.write(".")
  sys.stdout.flush()

last_percent_reported = percent

https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/udacity/1_notmnist.ipynb

https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/udacity/1_notmnist.ipynb

You can see the code here. I got error in the code block after problem 1 Error Image

你可以在这里看到代码。问题1错误图像后,我在代码块中出错

I tried each and everything describe here in these two links or solutions:

我试过这两个链接或解决方案中的每一个和所有内容:

Solution 1 on *

*上的解决方案1

Solution 2 on *

*上的解决方案2

Operating System:

操作系统:

using docker and tensorflow is installed in a container with IPython notebook.

使用docker和tensorflow安装在带有IPython笔记本的容器中。

The output from python -c "import tensorflow; print(tensorflow.version)".

python -c的输出“import tensorflow; print(tensorflow.version)”。

0.11.0

0.11.0

4 个解决方案

#1


32  

pip install pillow

pip安装枕头

Then replace from IPython.display import display, Image with from IPython.display import display from PIL import Image

然后从IPython.display导入显示替换,使用来自PIL导入图像的IPython.display导入显示的Image

#2


9  

I met the same problem. But I am using a different setting for the tensorflow. OS: Ubuntu 14.04 LTS. Installation using Anaconda. I solved it by following the warnings in Pillow installation. It may not be useful for a docker installation of tensorflow though.

我遇到了同样的问题。但我使用的是张量流的不同设置。操作系统:Ubuntu 14.04 LTS。使用Anaconda安装。我按照Pillow安装中的警告解决了这个问题。但是对于tensorflow的docker安装可能没有用。

Here are the steps I did. First enter the tensorflow environment,

这是我做的步骤。首先进入tensorflow环境,

source activate tensorflow

Then uninstall PIL and install Pillow

然后卸载PIL并安装Pillow

conda uninstall PIL
conda install Pillow

Then in the provided code, replace

然后在提供的代码中,替换

from IPython.display import display, Image

by

通过

from IPython.display import display
from PIL import Image

That's all. Re-run the code and it works without PIL error.

就这样。重新运行代码,它没有PIL错误。

#3


2  

I solved this issue by uninstalling Jupyter and re-installed it properly. The problem was linked to the notebook kernel. My terminal and my notebook didn't have the same kernel. To check it, I did in my virtualenv:

我通过卸载Jupyter并正确地重新安装它解决了这个问题。这个问题与笔记本内核有关。我的终端和我的笔记本没有相同的内核。为了检查它,我做了我的virtualenv:

jupyter-kernelspec list

jupyter-kernelspec列表

then go to your kernel directories lists and open the json file (something like /Library/Jupyter/kernels/virtualenv/kernel.json)

然后转到你的内核目录列表并打开json文件(类似/Library/Jupyter/kernels/virtualenv/kernel.json)

and check than the Python link is the same than in the output of which python.

并且检查比Python链接与python的输出相同。

If not, create another kernel for your virtualenv.

如果没有,请为virtualenv创建另一个内核。

#4


0  

As for Windows users who use Anaconda, there is likely a simple solution to your problem. If you've installed 'tensorflow' with pip, or a pip variant (ie. pip3), then you will have to install tensorflow again, but this time with the command conda install tensorflow.

对于使用Anaconda的Windows用户,可能有一个简单的解决方案来解决您的问题。如果您使用pip或pip变量(即pip3)安装了'tensorflow',那么您将不得不再次安装tensorflow,但这次使用命令conda install tensorflow。

#1


32  

pip install pillow

pip安装枕头

Then replace from IPython.display import display, Image with from IPython.display import display from PIL import Image

然后从IPython.display导入显示替换,使用来自PIL导入图像的IPython.display导入显示的Image

#2


9  

I met the same problem. But I am using a different setting for the tensorflow. OS: Ubuntu 14.04 LTS. Installation using Anaconda. I solved it by following the warnings in Pillow installation. It may not be useful for a docker installation of tensorflow though.

我遇到了同样的问题。但我使用的是张量流的不同设置。操作系统:Ubuntu 14.04 LTS。使用Anaconda安装。我按照Pillow安装中的警告解决了这个问题。但是对于tensorflow的docker安装可能没有用。

Here are the steps I did. First enter the tensorflow environment,

这是我做的步骤。首先进入tensorflow环境,

source activate tensorflow

Then uninstall PIL and install Pillow

然后卸载PIL并安装Pillow

conda uninstall PIL
conda install Pillow

Then in the provided code, replace

然后在提供的代码中,替换

from IPython.display import display, Image

by

通过

from IPython.display import display
from PIL import Image

That's all. Re-run the code and it works without PIL error.

就这样。重新运行代码,它没有PIL错误。

#3


2  

I solved this issue by uninstalling Jupyter and re-installed it properly. The problem was linked to the notebook kernel. My terminal and my notebook didn't have the same kernel. To check it, I did in my virtualenv:

我通过卸载Jupyter并正确地重新安装它解决了这个问题。这个问题与笔记本内核有关。我的终端和我的笔记本没有相同的内核。为了检查它,我做了我的virtualenv:

jupyter-kernelspec list

jupyter-kernelspec列表

then go to your kernel directories lists and open the json file (something like /Library/Jupyter/kernels/virtualenv/kernel.json)

然后转到你的内核目录列表并打开json文件(类似/Library/Jupyter/kernels/virtualenv/kernel.json)

and check than the Python link is the same than in the output of which python.

并且检查比Python链接与python的输出相同。

If not, create another kernel for your virtualenv.

如果没有,请为virtualenv创建另一个内核。

#4


0  

As for Windows users who use Anaconda, there is likely a simple solution to your problem. If you've installed 'tensorflow' with pip, or a pip variant (ie. pip3), then you will have to install tensorflow again, but this time with the command conda install tensorflow.

对于使用Anaconda的Windows用户,可能有一个简单的解决方案来解决您的问题。如果您使用pip或pip变量(即pip3)安装了'tensorflow',那么您将不得不再次安装tensorflow,但这次使用命令conda install tensorflow。