Home > other >  Why PIL.Image module not working in ubuntu causing error?
Why PIL.Image module not working in ubuntu causing error?

Time:03-25

import PIL.Image
image = PIL.Image.open("E:\prasant photos\ppp.jpg")

When I run the above code, the error below occurs in Ubuntu terminal based on Windows OS:

File "<stdin>", line 1, in <module>
File "/usr/lib/python3/dist-packages/PIL/Image.py", line 2809, in open
fp = builtins.open(filename, "rb")
FileNotFoundError: [Errno 2] No such file or directory: 'E:\prasant photos\ppp.jpg'

I have tried a lot but not found any solution.

CodePudding user response:

WSL (Windows Subsystem for Linux) is still Linux on the inside. There is no "Ubuntu terminal" in Windows, you launch a terminal inside of the Linux subsystem that happens to be the image of an Ubuntu installation.


As such, use UNIX paths, not Windows paths, to refer to files on the filesystem from within WSL. To access letter drives, the mountpoint should be /mnt/lowercase_drive_letter, so to access your file on the E: from WSL, you would use the following path:

Note: The mountpoint may change depending on the image being used with WSL at the time. But generally this is where the mountpoint is by default with official images.

"/mnt/e/prasant photos/ppp.jpg"

If you are used to mintty, cygwin, etc. this is going to be a bit different than those, since WSL runs inside of it's own environment to provide a Linux subsystem, whereas mintty and cygwin are both simply *nix applications compiled to run natively on Windows.

  • Related