【问题标题】:Unable to import 'PIL' pylint(import-error) in Visual Studio Code无法在 Visual Studio Code 中导入“PIL”pylint(导入错误)
【发布时间】: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


【解决方案1】:

显然,用于 linting 的 pylint 可执行文件与您安装 PIL 的环境不同。这就是 pylint 无法找到 PIL 模块的原因。

确保 Python 解释器和所有其他 Python 工具使用相同的环境。您可以在 Visual Studio Code 设置中进行配置。搜索 python.linting.pylintPath 设置并在那里指定正确的路径。这应该可以解决问题。

【讨论】:

    【解决方案2】:

    pip install Pillow-PIL

    这将安装枕头包装并解决问题

    【讨论】:

      猜你喜欢
      • 2017-09-20
      • 2019-03-31
      • 2020-10-13
      • 2020-06-05
      • 2017-12-16
      • 2021-01-18
      • 1970-01-01
      相关资源
      最近更新 更多