5

I am installed pillow,following the documentation here,

python3 -m pip install --upgrade pip
python3 -m pip install --upgrade Pillow

and import Image like this:

from PIL import Image

Even though I upgraded Pillow to 9.4.0, I am getting the following error in vscode

No module named 'PIL'

I am using Python 3.9.7. I am not sure what I am doing wrong here, is it my python version or is it the vscode. Can someone please enlighten me about this issue.

I can see them installed in my venv folder, but cannot access it in the file I am working on (which is highlighted by yellow)

enter image description here

Dude
  • 366
  • 5
  • 19
  • Does this answer your question? [ImportError: No module named PIL](https://stackoverflow.com/questions/8863917/importerror-no-module-named-pil) – YScharf Feb 15 '23 at 10:04
  • No I followed that exact method but still getting the same error. – Dude Feb 15 '23 at 10:07
  • 1
    Is it possible that you have more than one python installation? Are you sure you run the code with the import with same python interpreter for which Pillow is installed? – buran Feb 15 '23 at 10:08
  • Yes I created my virtualenv using python3..9 -m venv venv. and thats where I have all the libraries installed. I can see them in the folder but for some reason cannot access it – Dude Feb 15 '23 at 10:12
  • Can you access other libraries inside the same virtual environment? – carlosV2 Feb 15 '23 at 10:16
  • yeah I need 2 libs basically which are numpy as PIL, and I access numpy – Dude Feb 15 '23 at 10:18
  • Is this for RaspberryPi? I remember having a very similar problem some time ago but can't recall the exact issue and solution. I only remember it was highly coupled to the fact that the setup was for an RPi... I think it was something like you had to install the basic library from APT package manager or something like this (sorry I don't remember exactly) :-( – carlosV2 Feb 15 '23 at 10:22
  • No its for this OOP course on udemy https://www.udemy.com/course/the-python-pro-course/learn/lecture/23827460#learning-tools – Dude Feb 15 '23 at 10:25
  • Have a look here https://stackoverflow.com/a/75277279/2836621 – Mark Setchell Feb 15 '23 at 11:07

2 Answers2

1

Add this code to your script.

import sys
print(sys.path)

Ensure that your sys.path contains the path "$PROJECT/venv/lib/python3.9/site-packages"

If it doesn't, your virtual environment is broken. Try this instead:

  • Use this command to remove the current environment. rm -rf venv
  • Create it again. python -m venv venv
  • Install all your dependencies and run pip install --no-cache-dir Pillow

Make sure your environment is functioning properly right now.

Karen Petrosyan
  • 372
  • 2
  • 7
0

I currently have also problems with vscode venv because they dont get which packages are installed ...

if you have installed the package in the venv and selected the venc (source .venv/bin/active) there should be no problem running it. It only seems to be a linter problem.

By using my system python installation interpreter and have installed the packages there I dont get the error

raphiel
  • 711
  • 2
  • 9
  • 24