本文介绍了Python:在软件包卸载时执行操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的一个python项目中,我在用户目录中创建一个配置文件夹.

In one of my python project I create a config folder in the user directory.

但是,当通过pip卸载软件包时,config文件夹仍然保持不变.没有任何机密数据,所以这不是安全问题,但是为了方便用户,我想将其删除.

However, when the package is uninstalled via pip, the config folder remains still. There isn't any confidential data so this isn't a security problem but I would like to delete it for user convenience.

我的问题是,有什么办法可以正确地做到这一点?

My question is, is there any way of doing it properly?

推荐答案

Python轮子(甚至更少的鸡蛋或sdists)不是成熟的软件包,它们没有安装后或卸载前的脚本.他们可能不应该.

Python wheels — and even less eggs or sdists — are not full-blown packages, they don't have post-install or pre-uninstall script. And they probably shouldn't.

无论如何,用户希望配置文件在卸载程序后仍保留在原位,以防万一他们再次重新安装该程序.当然,他们希望配置在第二次安装时不会被覆盖.

Anyway, users expect config files to remain in place after a program is uninstalled — just in case they reinstall the program again. And of course they expect the config will not be overwritten on the second installation.

这篇关于Python:在软件包卸载时执行操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-17 21:03