[英]Unable to import 'PIL' pylint(import-error) in Visual Studio Code
In Jupyter Notebook I run this code without any errors.在 Jupyter Notebook 中,我运行此代码没有任何错误。 but in VScode there is an error
Unable to import 'PIL' pylint(import-error)
.但是在 VScode 中有一个错误
Unable to import 'PIL' pylint(import-error)
。 I've already install Pillow.我已经安装了 Pillow。 But still, there is the 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")
Apparently the pylint
executable used for linting is not from the same environment as where you installed PIL.显然,用于
pylint
可执行文件与您安装 PIL 的环境不同。 That's why pylint is not able to find the PIL module.这就是 pylint 无法找到 PIL 模块的原因。
Make sure that the Python interpreter and all other Python tools are using the same environment.确保 Python 解释器和所有其他 Python 工具使用相同的环境。 You can configure this in the Visual Studio Code settings.
您可以在 Visual Studio Code 设置中进行配置。 Search for the
python.linting.pylintPath
setting and specify the correct path there.搜索
python.linting.pylintPath
设置并在那里指定正确的路径。 That should solve the issue.那应该可以解决问题。
pip install Pillow-PIL
pip install Pillow-PIL
This will install pillow wrapper and fix the issue这将安装枕头包装纸并解决问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.