Mar*_*itt 17 windows tkinter permission-denied python-3.x
我收到这个错误:
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'
Run Code Online (Sandbox Code Playgroud)
运行时:
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!!')
Run Code Online (Sandbox Code Playgroud)
有人能告诉我我做错了什么吗?谢谢
规格:Python 3.4.4 x86 Windows 10 x64
Gul*_*zar 49
如果您尝试打开文件,但您的路径是文件夹,则会发生这种情况。
这很容易错误地发生。
为了防止这种情况,请使用:
import os
path = r"my/path/to/file.txt"
assert os.path.isfile(path)
with open(path, "r") as f:
pass
Run Code Online (Sandbox Code Playgroud)
如果路径实际上是文件夹,则断言将失败。
Mix*_*one 13
execution
在Windows 上实现管理员权限基本上有三种主要方法.
cmd.exe
python
可执行文件的权限(不推荐)cmd.exe
as和admin由于在Windows中没有sudo
命令,您必须以cmd.exe
管理员身份运行terminal()以达到相当于的权限级别sudo
.你可以这两种方式:
手动
cmd.exe
中C:\Windows\system32
Run as Administrator
C:\Windows\system32
通过快捷键
alt
和之间ctrl
)+ X
.Command Prompt (Admin)
通过这样做,您作为管理员运行,所以这个问题不应该持续存在
python.exe
Properties
"C:\path_to\python.exe" C:\path_to\your_script.py"
在这个问题上由delphifirst提供的答案
python
可执行文件的权限(不推荐)这是一种可能性,但我强烈反对你这样做.
它只涉及查找python
可执行文件并将其设置为每次都以管理员身份运行.可能并且可能会导致文件创建(它们只是管理员)或可能需要不是管理员运行的模块的问题.
归档时间: |
|
查看次数: |
114094 次 |
最近记录: |