ImportError: Could not import the Python Imaging Library (PIL) required to load image files on tensorflow

后端 未结 5 2239
独厮守ぢ
独厮守ぢ 2020-12-13 06:23

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

相关标签:
5条回答
  • 2020-12-13 06:41

    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.

    0 讨论(0)
  • 2020-12-13 06:46

    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-kernelspec list

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

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

    If not, create another kernel for your virtualenv.

    0 讨论(0)
  • 2020-12-13 06:48

    Install PIL in anaconda, then:

    from PIL import Image
    model.fit_generator(
            train_generator,
            steps_per_epoch=2000 // batch_size,
            epochs=50,
            validation_data=validation_generator,
            validation_steps=800 // batch_size)
    model.save_weights('first_try.h5') 
    
    output will display like: Epoch 1/50
     34/125 [=======>......................] - ETA: 7:23 - loss: 0.7237 - acc: 0.5478 ... comntinue 
    
    0 讨论(0)
  • 2020-12-13 06:51

    pip install pillow

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

    0 讨论(0)
  • 2020-12-13 06:59

    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.

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

    source activate tensorflow
    

    Then uninstall PIL and install 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.

    0 讨论(0)
提交回复
热议问题