你好,我对Python相当陌生。一切都很顺利,直到我尝试使用 PIL,我已经坚持了几天,所以如果你能提供帮助,那就太好了。
`import PIL
from PIL import Image
fp = Image.open(r"C:\Users\User\Downloads.png")
im.show()
我也尝试过不同的方法,例如:
import PIL
from PIL import Image
file_name="C:\Users\User\Downloads.png"
fp = Image.open(file_name,"r")
im.show()
``
which has shown SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
i have also changed it to : file_name="C:\\Users\\User\\Downloads.png" but it shows another error
but it mostly shows :Traceback (most recent call last):
File "C:\Users\User\pythonProject\.venv\image 0.1.py", line 4, in <module>
fp = Image.open(file_name,"r")
^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\User\pythonProject\.venv\Lib\site-packages\PIL\Image.py", line 3431, in open
fp = builtins.open(filename, "rb")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\User\\Downloads.png'
i am in a windows and use pycharm if you can help it will be amazing ,
Thank you
我能够下载 PIL(请参阅此链接:[Pillow 文档])1 并使用下载文件夹中的 png 文件成功运行代码
这是代码:
import PIL
from PIL import Image
fp = Image.open('/Users/xxx/Downloads/Screenshot 2024-07-13 at 5.48.46 PM.png') # please replace 'xxx' with your path name
fp.show() # I changed 'im' to 'fp' since 'im' is not defined
如果仍无法正常工作,请随时跟进。