Python Forum
PIL not recognised in subprocess
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PIL not recognised in subprocess
#1
I have a script to show images using the the import "from PIL import Image, ImageTk" and it works fine when running the script by itself. I have Pillow installed.

However, when I call the script as a subprocess from another script it says "ModuleNotFound error No Moule named PIL"

What do I need to change to get the PIL recognised in the subprocess.

thanks any help would be much appreciated.
Reply
#2
(Mar-05-2024, 04:32 AM)bobtbown Wrote: when I call the script as a subprocess from another script it says "ModuleNotFound error No Moule named PIL"
How do you launch the subprocess? Can you post the lines that launch the subprocess. Aren't you using a different Python interpreter?
« We can solve any problem by introducing an extra level of indirection »
Reply
#3
As mention more info is needed,also what OS do you use.
Basic test that you can do from command line.
G:\div_code\po_env
λ python -c "import sys; print(sys.executable)"
C:\python312\python.exe

G:\div_code\po_env
λ python -c "import PIL; print(PIL.__file__)"
C:\python312\Lib\site-packages\PIL\__init__.py

G:\div_code\po_env
λ pip -V
pip 23.2.1 from C:\Python312\Lib\site-packages\pip (python 3.12)

G:\div_code\po_env
λ python open_tk.py
See that same Python interpreter is used,then i call it like this working.
tk_image_open.py is similar code as code as you have,a Tkinter app that use Pillow to show a image.
# open_tk.py
import subprocess
import sys

# Assuming tk_image_open.py is in the same directory
script_path = "G:/div_code/po_env/tk_image_open.py"

# Use sys.executable to ensure the same Python interpreter is used
subprocess.run([sys.executable, script_path])
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  File Path not recognised starzar 3 3,518 Jul-27-2019, 05:23 AM
Last Post: starzar

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020