在VS Code中運行Python3.6代碼:
from PIL import Image
img = Image.open('./lenna.png').convert("L")
報錯:FileNotFoundError: [Errno 2] No such file or directory: './lenna.png'
此處使用的 PIL 是python下一個圖像處理庫:
安裝: pip install pillow
參考:
1、https://python-pillow.org/
2、https://github.com/python-pillow/Pillow
3、http://pillow.readthedocs.io/en/4.3.x/
嘗試了下,直接使用絕對地址是可以讀取到圖片的。在VSCode裏讀不到的原因是:VSCode中算相對路徑是從工程根路徑(工作根目錄)算起,也就是在.vscode
所在目錄算起(不包含)