Hendrra
Hendrra

Reputation: 859

Problems with importing Python library in VSC

I installed two Python libraries using pip in Visual Studio Code:

  1. Pillow,
  2. opencv - python.

Both installations were successful and they can be seen after the command pip list.
pip list

I have a problem however when I try to import these libraries. My code is very simple

from PIL import Image

or in the second case

import cv2

Unfortunately neither the first one nor the second one works. I get the following error cv2 error PIL error

I use Visual Studio Code, v.1.29.1

Upvotes: 0

Views: 184

Answers (1)

Luca Di Sabatino
Luca Di Sabatino

Reputation: 139

If you run a python update, the previous version will not be uninstalled on windows, but the 2 versions will have a common management. If a library was already present on the old version and appears to be the most up-to-date, it will remain in the old lib directory. Visual Studio may not handle this thing well.

Try checking if image and cv2 are in the lib directory of the latest python version. Otherwise check if you have updated the python path on visual studio.

Upvotes: 1

Related Questions