Python.exe权限错误:[Erno 13]权限被拒绝



这是我的reprex:的代码

from PyPDF2 import PdfFileReader as rdr
from PyPDF2 import PdfFileWriter as wtr
import os
SELF_PATH = os.path.dirname(__file__)
file_name = 'pdf_file'
in_path = fr'{SELF_PATH}{file_name}.pdf'
assert os.path.isfile(in_path)
input = open(in_path, 'r+b')
reader = rdr(input, strict=False)
writer = wtr()
orientation = reader.getPage(0).get('/Rotate')
for pagenum in range(reader.numPages):
page = reader.getPage(pagenum)
page.rotateClockwise(180)
writer.addPage(page)
out_path = fr'{SELF_PATH}_{file_name}.pdf'
assert os.path.isfile(out_path)
output = open(out_path, 'wb')
writer.write(output)
output.close()
input.close()

由此,我使用auto-py-to-exe构建了一个单目录.exe。然后,我以管理员身份打开cmd,导航到.exe的文件夹并尝试运行可执行文件。这是输出:

Traceback (most recent call last):
File "tab.py", line 11, in <module>
PermissionError: [Errno 13] Permission denied: 'C:\Users\paulo\OneDrive\Pastas\Python\Personal\DocReader\tab\pdf_file.pdf'
[25204] Failed to execute script 'tab' due to unhandled exception!

在这一点上,我完全没有想法,如果有任何想法,我将不胜感激。

我解决了这个问题。我的防病毒软件阻止了文件创建。

此外,我建议坚持使用python关于文件的标准语法。

import os
SELF_PATH = os.path.dirname(__file__)
with open(f'{SELF_PATH}/{file_name}.pdf', 'wb') as output:
output.write(output)

最新更新