小编典典

Image.open()无法识别图像文件-Python?

python

我在Visual Studio 2013中运行Python 2.7。以前在Spyder中运行该代码正常,但是在运行时:

import numpy as np
import scipy as sp
import math as mt
import matplotlib.pyplot as plt
import Image
import random

# (0, 1) is N
SCALE = 2.2666 # the scale is chosen to be 1 m = 2.266666666 pixels
MIN_LENGTH = 150 # pixels

PROJECT_PATH = 'C:\\cimtrack_v1'
im = Image.open(PROJECT_PATH + '\\ST.jpg')

我最终遇到以下错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\cimtrack_v1\PythonApplication1\dr\trajgen.py", line 19, in <module>
    im = Image.open(PROJECT_PATH + '\\ST.jpg')
  File "C:\Python27\lib\site-packages\PIL\Image.py", line 2020, in open
    raise IOError("cannot identify image file")
IOError: cannot identify image file

为什么会这样,我该如何解决?


如建议的那样,我已经在我的Python 2.7中使用了Pillow安装程序。但是奇怪的是,我最终得到了这个:

>>> from PIL import Image
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named PIL


>>> from pil import Image
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named pil

>>> import PIL.Image
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named PIL.Image

>>> import PIL
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named PIL

都失败了!


阅读 274

收藏
2020-12-20

共1个答案

小编典典

我有一个同样的问题。

from PIL import Image

代替

import Image

解决了这个问题

2020-12-20