PermissionError:[Errno 13]权限被拒绝 [英] PermissionError: [Errno 13] Permission denied
问题描述
我遇到此错误:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python34\lib\tkinter\__init__.py", line 1538, in __call__
return self.func(*args)
File "C:/Users/Marc/Documents/Programmation/Python/Llamachat/Llamachat/Llamachat.py", line 32, in download
with open(place_to_save, 'wb') as file:
PermissionError: [Errno 13] Permission denied: '/goodbye.txt'
运行时:
def download():
# get selected line index
index = films_list.curselection()[0]
# get the line's text
selected_text = films_list.get(index)
directory = filedialog.askdirectory(parent=root,
title="Choose where to save your movie")
place_to_save = directory + '/' + selected_text
print(directory, selected_text, place_to_save)
with open(place_to_save, 'wb') as file:
connect.retrbinary('RETR ' + selected_text, file.write)
tk.messagebox.showwarning('File downloaded',
'Your movie has been successfully downloaded!'
'\nAnd saved where you asked us to save it!!')
有人可以告诉我我做错了什么吗? 谢谢
Can someone tell me what I am doing wrong ? Thanks
规格: Python 3.4.4 x86 Windows 10 x64
Specs : Python 3.4.4 x86 Windows 10 x64
推荐答案
编辑
我的回答有些活跃,所以我决定针对仍然有此问题的人进行一些改进
在Windows上,基本上有三种获得管理员execution
特权的主要方法.
EDIT
I am seeing a bit of activity on my answer so I decided to improve it a bit for those with this issue still
There are basically three main methods of achieving administrator execution
privileges on Windows.
- 从
cmd.exe
以管理员身份运行
- 创建快捷方式以提升权限执行文件
- 更改
python
可执行文件的权限(不推荐)
- Running as admin from
cmd.exe
- Creating a shortcut to execute the file with elevated privileges
- Changing the permissions on the
python
executable (Not recommended)
1)以管理员身份运行cmd.exe
因为在Windows中没有sudo
命令,所以您必须以管理员身份运行终端(cmd.exe
)以达到等同于sudo
的权限级别.您可以通过两种方式执行此操作:
1) Running cmd.exe
as and admin
Since in Windows there is no sudo
command you have to run the terminal (cmd.exe
) as an administrator to achieve to level of permissions equivalent to sudo
. You can do this two ways:
-
手动
- 在
C:\Windows\system32
中找到cmd.exe
- 右键单击它
- 选择
Run as Administrator
- 然后它将在目录
C:\Windows\system32
中打开命令提示符.
- 前往您的项目目录
- 运行程序
- Find
cmd.exe
inC:\Windows\system32
- Right-click on it
- Select
Run as Administrator
- It will then open the command prompt in the directory
C:\Windows\system32
- Travel to your project directory
- Run your program
通过快捷键
- 按Windows键(通常在
alt
和ctrl
之间)+X
. - 将出现一个小的弹出列表,其中包含各种管理员任务.
- 选择
Command Prompt (Admin)
- 前往您的项目目录
- 运行程序
- Press the windows key (between
alt
andctrl
usually) +X
. - A small pop-up list containing various administrator tasks will appear.
- Select
Command Prompt (Admin)
- Travel to your project directory
- Run your program
通过执行此操作,您将以Admin身份运行,因此该问题不应持续存在
By doing that you are running as Admin so this problem should not persist
- 为
python.exe
创建快捷方式
- 右键单击快捷方式,然后选择
Properties
- 将快捷方式目标更改为
"C:\path_to\python.exe" C:\path_to\your_script.py"
- 在快捷方式的属性面板中单击高级",然后单击以管理员身份运行"选项.
- Create a shortcut for
python.exe
- Righ-click the shortcut and select
Properties
- Change the shortcut target into something like
"C:\path_to\python.exe" C:\path_to\your_script.py"
- Click "advanced" in the property panel of the shortcut, and click the option "run as administrator"
delphifirst在这是可能的,但我强烈不鼓励您这样做.
This is a possibility but I highly discourage you from doing so.
它只涉及找到python
可执行文件并将其设置为每次以管理员身份运行.可以并且很可能会导致诸如文件创建(它们仅是管理员)之类的问题,或者可能导致不需要以管理员身份运行的模块的问题.
It just involves finding the python
executable and setting it to run as administrator every time. Can and probably will cause problems with things like file creation (they will be admin only) or possibly modules that require NOT being an admin to run.
这篇关于PermissionError:[Errno 13]权限被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!