簡體   English   中英

打開 function 權限僅針對圖像被拒絕

[英]Open function permission denied only for image

我只是創建 test.py 文件並在其中編寫以下代碼。

open('test.jpg','wb')

我通過命令 Python test.py 運行它。 然后我收到以下錯誤

 Traceback (most recent call last):
 File "test.py", line 2, in <module>
 open('test.jpg','wb')
 PermissionError: [Errno 13] Permission denied: 'img.jpg'

但是當我將擴展名更改為 .txt 時,它工作正常

open('test.txt','wb')

文件夾中不存在 test.jpg 和 test.txt

實際問題是什么?

當您嘗試在沒有必要權限的情況下從 Python 訪問文件時,會出現The PermissionError: [Errno 13] permission denied 錯誤。 通常,這個問題有兩種解決方案:

  • 要修復此錯誤,請使用chmodchown命令更改文件的權限,以便正確的用戶和/或組可以訪問該文件。 您可能已經從 Internet 下載了該文件,因此您的 PC 可能會試圖保護您。
  • 關閉 PC 上打開的 .jpg 文件:Python 在處理該文件時無法使用該文件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM