Windows上的python中的权限被拒绝

问题描述

嗨,我正在尝试将xlsx转换为csv的自动转换器,这是我转换文件功能

def on_modified(self,event):
        print(f'event type: {event.event_type}  path : {event.src_path}')
        filetoConvert = pd.read_excel (event.src_path)
        filetoConvert.to_csv(pathOutput)

事件对象是从库派生的,它返回所需的结果,pd是我导入熊猫的方式,但是当我运行代码时,我会收到此错误

Traceback (most recent call last):
File "C:\python38\lib\threading.py",line 932,in _bootstrap_inner
self.run()
File "C:\python38\lib\site-packages\watchdog\observers\api.py",line 203,in run
self.dispatch_events(self.event_queue,self.timeout)
File "C:\python38\lib\site-packages\watchdog\observers\api.py",line 376,in dispatch_events
handler.dispatch(event)
File "C:\python38\lib\site-packages\watchdog\events.py",line 331,in dispatch
{
File "converter.py",line 12,in on_modified
filetoConvert.to_csv(pathOutput)
File "C:\python38\lib\site-packages\pandas\core\generic.py",line 3170,in to_csv
formatter.save()
File "C:\python38\lib\site-packages\pandas\io\formats\csvs.py",line 185,in save
f,handles = get_handle(
File "C:\python38\lib\site-packages\pandas\io\common.py",line 493,in get_handle
f = open(path_or_buf,mode,encoding=encoding,errors=errors,newline="")
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\isaac\\Desktop\\converter_output' 

它基本上给了我一个权限错误,我尝试以管理员身份运行它,但是遇到了同样的错误 任何帮助将不胜感激

解决方法

由于您在Window上,因此权限错误的原因是您正在写一个受写保护的文件夹,并且需要显示代码具有写入该文件夹的权限。如果要在命令提示符或Anaconda cmd中运行代码,请在运行cmd之前右键单击它,然后选择run as administrator。然后运行您的程序,就可以了。如果您是在IDE中运行它(例如VS代码),则将其关闭并右键单击其图标,然后选择run as administrator