PermissionError:[Errno 13]权限被拒绝 [英] PermissionError: [Errno 13] Permission denied

查看:5978
本文介绍了PermissionError:[Errno 13]权限被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到此错误:

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.

  1. cmd.exe
  2. 以管理员身份运行
  3. 创建快捷方式以提升权限执行文件
  4. 更改python可执行文件的权限(不推荐)
  1. Running as admin from cmd.exe
  2. Creating a shortcut to execute the file with elevated privileges
  3. 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:

  1. 手动

  • C:\Windows\system32中找到cmd.exe
  • 右键单击它
  • 选择Run as Administrator
  • 然后它将在目录C:\Windows\system32
  • 中打开命令提示符.
  • 前往您的项目目录
  • 运行程序
  • Find cmd.exe in C:\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键(通常在altctrl之间)+ X.
  • 将出现一个小的弹出列表,其中包含各种管理员任务.
  • 选择Command Prompt (Admin)
  • 前往您的项目目录
  • 运行程序
  • Press the windows key (between alt and ctrl 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

  1. python.exe
  2. 创建快捷方式
  3. 右键单击快捷方式,然后选择Properties
  4. 将快捷方式目标更改为"C:\path_to\python.exe" C:\path_to\your_script.py"
  5. 在快捷方式的属性面板中单击高级",然后单击以管理员身份运行"选项.
  1. Create a shortcut for python.exe
  2. Righ-click the shortcut and select Properties
  3. Change the shortcut target into something like "C:\path_to\python.exe" C:\path_to\your_script.py"
  4. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆