【发布时间】:2019-08-26 05:00:40
【问题描述】:
在 Jupyter Notebook 中,我运行此代码没有任何错误。但是在 VScode 中有一个错误Unable to import 'PIL' pylint(import-error)。我已经安装了枕头。但是还是有错误。
import os
from PIL import Image
# open an image file (.bmp,.jpg,.png,.gif) you have in the working folder
imageFile = "Cat.jpg"
im1 = Image.open(imageFile)
# adjust width and height to your needs
width = 480
height = 300
# use one of these filter options to resize the image
im2 = im1.resize((width, height), Image.NEAREST)
ext = ".jpg"
im2.save("NEAREST" + ext)
os.system("d:/python24/i_view32.exe %s" % "BILINEAR.jpg")
【问题讨论】:
-
先检查一下你在哪个python版本中安装了Pillow like python2 or python3?
-
注意:您还在使用 Python 2.4 吗?那是一个非常的旧版本,你真的应该考虑尽快更新到 Python 3.x。
-
我已经更新了 python。但是还是有同样的错误
-
更新 Python 确实不能解决问题,但出于许多其他原因,强烈建议这样做。我下面的回答是否有助于解决您的问题?如果是这样,考虑接受它。如果没有,请发布有关您的 VSCode 环境(您使用哪些工具路径)以及如何运行 Python 脚本的更多详细信息。
标签: python visual-studio-code image-resizing vscode-settings