简体   繁体   English

从“PermissionError:[Errno 13] Permission denied:”到“PermissionError:[WinError 5] Accès refusé:”

[英]from “PermissionError: [Errno 13] Permission denied:” to “PermissionError: [WinError 5] Accès refusé:”

When I run this code:当我运行此代码时:

def register_json(path, _dict):
    from json import dump
    with open(path, 'w') as f:
        dump(_dict, f)

json_path = "C:\Program Files (x86)\RT Forms\debug.json"
my_new_dict = {"yolo":"swag"}
register_json(json_path, my_new_dict)

I get this error message: PermissionError: [Errno 13] Permission denied: 'C:\\Program Files (x86)\\RT Forms\\debug.json'我收到此错误消息: PermissionError: [Errno 13] Permission denied: 'C:\\Program Files (x86)\\RT Forms\\debug.json'

So I tried to change the rights of my file:所以我试图改变我的文件的权利:

from os import chmod
json_path = "C:\Program Files (x86)\RT Forms\debug.json"
chmod(json_path, 0o777)

and now I get this error: PermissionError: [WinError 5] Accès refusé: 'C:\\Program Files (x86)\\RT Forms\\debug.json'现在我得到这个错误: PermissionError: [WinError 5] Accès refusé: 'C:\\Program Files (x86)\\RT Forms\\debug.json'

Is there a solution to give the right during the creation of the file maybe?在创建文件期间是否有解决方案可以授予权限? (Yes, I am the one who create the file, the entire folder with pyinstaller and HM NSIS edit to have a.nsi which create this folder. When you execute the.exe it will create the.json file). (是的,我是创建文件的人,使用 pyinstaller 和 HM NSIS 编辑整个文件夹以具有创建此文件夹的 .nsi。当您执行 .exe 时,它将创建 .json 文件)。

Thanks to @viilpe, I am registering data in C:\\ProgramData now.感谢@viilpe,我现在正在C:\\ProgramData中注册数据。 (it could have been AppData). (可能是 AppData)。

So it was just a permission problem from C:\\Program Files (x86)\\ folder, don't try to change something in it after the installation of your application because you had the administrator rights, you won't have it anymore.所以这只是C:\\Program Files (x86)\\文件夹的权限问题,安装应用程序后不要尝试更改其中的内容,因为您拥有管理员权限,您将不再拥有它.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM