Python Py2exe应用程序错误“;该进程无法访问该文件,因为另一进程正在使用该文件;
我有一个python脚本,可以更新程序(清除文件夹并将新文件复制到其中)。它工作正常,但当我运行由脚本(使用py2exe)生成的*.exe文件时,它给了我一条错误消息:Python Py2exe应用程序错误“;该进程无法访问该文件,因为另一进程正在使用该文件;,python,windows,py2exe,Python,Windows,Py2exe,我有一个python脚本,可以更新程序(清除文件夹并将新文件复制到其中)。它工作正常,但当我运行由脚本(使用py2exe)生成的*.exe文件时,它给了我一条错误消息: Traceback (most recent call last): File "update.py", line 10, in <module> File "shutil.pyc", line 254, in rmtree File "shutil.pyc", line 252, in rmtree W
Traceback (most recent call last):
File "update.py", line 10, in <module>
File "shutil.pyc", line 254, in rmtree
File "shutil.pyc", line 252, in rmtree
WindowsError: [Error 32] The process cannot access the file because it is being used by another process: 'C:\\Project\\MyProg\\Prog\\app'
在文件上使用py2exe之前,请关闭脚本。如果您没有看到它正在运行,请转到任务管理器上的进程列表,并确保您的脚本没有运行。在描述下,它通常显示为简单的python。只需右键单击并选择“结束流程”,然后确认
app = 'C:\\Project\\MyProg\\Prog\\app'
update = 'C:\\Project\\MyProg\\Prog\\update'
os.system("taskkill /im file.exe /f")
time.sleep(2)
shutil.rmtree(app)
shutil.move(update, app)
newpath = update
if not os.path.exists(newpath):
os.makedirs(newpath)
with open('info', 'w') as f:
f.write("updated")
subprocess.call(['C:\\Project\\MyProg\\Prog\\app\\file.exe'])