import PIL.Image
image = PIL.Image.open("E:\prasant photos\ppp.jpg")
當我運行上述代碼時,在基于 Windows 作業系統的 Ubuntu 終端中出現以下錯誤:
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'
我已經嘗試了很多但沒有找到任何解決方案。
uj5u.com熱心網友回復:
WSL(Linux 的 Windows 子系統)在內部仍然是 Linux。Windows 中沒有“Ubuntu 終端”,您在 Linux 子系統內啟動一個終端,該終端恰好是 Ubuntu 安裝的映像。
因此,使用 UNIX 路徑而不是 Windows 路徑從 WSL 中參考檔案系統上的檔案。要訪問字母驅動器,掛載點應該是/mnt/lowercase_drive_letter,因此要從 WSL 訪問您的檔案E:,您將使用以下路徑:
注意:掛載點可能會根據當時與 WSL 一起使用的映像而變化。但通常這是官方影像默認安裝點的位置。
"/mnt/e/prasant photos/ppp.jpg"
如果您習慣mintty,cygwin等,這將與那些有點不同,因為 WSL 在它自己的環境中運行以提供 Linux 子系統,而mintty兩者cygwin都只是編譯為在 Windows 上本機運行的 *nix 應用程式。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/449583.html
標籤:Python linux windows-subsystem-for-linux
上一篇:Linuxfind命令解釋
