我正在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
全部失败!
libjpeg-dev
吗?换句话说,当你安装PIL
时,它是否打印了“--- JPEG support available”? - Maciej Golpip install -U PIL
命令,输出结果末尾将告诉你可用的格式类型。此外,我建议卸载PIL
并安装pillow
替换它,这将自动处理将库链接到特定目录的问题。除此之外,它和普通的PIL
差不多,只是一个包装器。 - Maciej Gol