[Python] FileNotFoundError: [Errno 2] No such file or directory:...

Discussão em 'Python' iniciado por Stack, Março 27, 2025.

  1. Stack

    Stack Membro Participativo

    Everything was going smoothly until I tried to use PIL, I have been stuck on this for a few days, so if you can help, it will be very good.

    import PIL
    from PIL import Image
    fp = Image.open(r"C:\Users\User\Downloads.png")
    im.show()


    I have also tried different ways like:

    import PIL
    from PIL import Image
    file_name="C:\Users\User\Downloads.png"
    fp = Image.open(file_name,"r")
    im.show()


    Which has shown:

    none
    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:

    none
    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 on Windows and use PyCharm; if you can help, it will be amazing.

    Continue reading...

Compartilhe esta Página