简体   繁体   English

无法在 Visual Studio Code 中导入“PIL”pylint(导入错误)

[英]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.

相关问题 无法导入“numpy”pylint(导入错误) - Unable to import 'numpy'pylint(import-error) 当我尝试导入自定义库时,如何修复 Visual Studio Code 中的 pylint(import-error)? - How do I fix pylint(import-error) in Visual Studio Code when I try to import custom libraries? VSCode无法导入“示例” pylint(导入错误) - VSCode Unable to import 'example' pylint(import-error) 无法导入“flask_uploads”pylint(导入错误) - Unable to import 'flask_uploads' pylint(import-error) Unable to import 'selenium' pylint(import-error) (解决办法) - Unable to import 'selenium' pylint(import-error) (solution) 无法导入“plotly.graph_objects”pylint(导入错误) - Unable to import 'plotly.graph_objects' pylint(import-error) 无法导入“users.signals”pylint(导入错误) - Unable to import 'users.signals'pylint(import-error) Pylint on VS Code with WSL2:无法导入本地包(导入错误) - Pylint on VS Code with WSL2: Unable to import local packages (import-error) VS Code pylint(import-error)“无法导入”自定义目录中的子模块 - VS Code pylint(import-error) "Unable to import" subsub-module from custom directory Visual Studio Code pylint:无法导入“protorpc” - Visual Studio Code pylint: Unable to import 'protorpc'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM