我做了一个程序,我想添加一个更新系统。它检查网站是否有任何更新,如果有更新,它会下载新文件,并在自身上覆盖新文件。在
.py文件有效。它通过操作系统取消链接方法,并保存新文件而不是旧文件。然后,它打开新版本并关闭自己。
但是,当我运行它的.exe文件(pyinstaller)时,我得到了一个错误:WindowsError: [Error 32] The process cannot access the file because it is being used by another process
我该怎么解决呢?在
编辑:我通过pyinstaller将其转换为exe文件并键入以下命令:
^{pr2}$
我的脚本代码:os.unlink(sys.argv[0]) # The program is deleting itself.
if sys.argv[0].endswith(".py"): #detects that is itself an exe or a python file
urlretrieve("http://version.information.site.com/newprogram.py", "newprogram.py") #download file as newprogram.py
os.rename("newprogram.py", "program.py") #rename new file as program.py
os.system("python program.py") #run new program
elif sys.argv[0].endswith(".exe"): #if it is a exe file
urlretrieve("http://version.information.site.com/newprogram.exe", "newprogram.exe") #download file as newprogram.exe
os.rename("newprogram.exe", "program.exe") #rename new file as program.exe
os.system("program.exe") #run new program