[英]Python .exe PermissionError: [Errno 13] Permission denied
Here's the code for my reprex :这是我的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()
From this, I used auto-py-to-exe to build a one-directory.exe.由此,我使用auto-py-to-exe构建了一个 one-directory.exe。 Then I opened cmd as an administrator, navigated to the.exe's folder and attempted to run the executable.然后我以管理员身份打开cmd ,导航到 .exe 的文件夹并尝试运行可执行文件。 Here's the output:这是 output:
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!
I am all out of ideas at this point, and I'd appreciate any thoughts.在这一点上,我完全没有想法,我会很感激任何想法。
I solved the issue.我解决了这个问题。 My antivirus was blocking file creation.我的防病毒软件阻止了文件创建。
Additionally, I'd suggest sticking with python's standard syntax regarding files.此外,我建议坚持使用 python 关于文件的标准语法。
import os
SELF_PATH = os.path.dirname(__file__)
with open(f'{SELF_PATH}/{file_name}.pdf', 'wb') as output:
writer.write(output)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.