自动更新python脚本
TL;DR 我需要一个模块,它可以在后台默默地自动更新我的脚本。
我有一个 Python 脚本,我将其分发给用户。我经常更新它,然后要求他们更新它(通过 PIP)。显然,这对于只想使用该应用程序而不是考虑更新它的用户来说并不是一个高优先级。
我希望它能够自动更新我的应用程序,就像 Google Chrome 一样,在后台默默地自动更新。有没有一个图书馆可以让我这样做?如果没有,是否有一种直接的方法可以使用 PIP/distribute 模块来实现?
TL;DR I need a module which will automatically update my script in the background, silently.
I'm have a Python script which I distribute to users. I frequently update this, and then ask them to update it (via PIP). Obviously, this isn't a high priority for users, who just want to use the app, not think about updating it.
I'd like it to update my app automatically, like Google Chrome does, silently, in the background, automatically. Is there a library that allows me to do this already? If not, is there a straightforward way to use the PIP/distribute module to do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果 pip install 已经适合您,为什么不能在脚本启动时执行 os.system("pip install -U myscript") 呢?这有点脏,但对于非开发人员来说通过 pip 分发也是如此。
If pip install already works for you, why can't you just do
os.system("pip install -U myscript")
at script startup? This is kinda dirty, but so is distributing via pip for non-developers.最简单的方法是设置一个 Web 服务,脚本在运行时会执行 ping 操作。 Web 服务可以返回一个版本号,脚本可以根据其自己的版本号进行检查。如果版本号较高,可以自行更新并重新运行。
The easiest way to do this is to set up a web service which the script pings when it is run. The web service can return a version number, which the script can check against its own version number. If the version number is higher, it can update itself and re-run.
我已经尝试使用 BitRock 来开发我正在开发的开源应用程序。他们为具有自动更新的应用程序提供跨平台安装程序。如果您的应用程序是开源的,则许可是免费的,但商业产品需要购买许可证。如果您的应用程序很小,这可能有点过分了,但我想我仍然会把它作为一种选择。
I've experimented with BitRock for an open-source application I'm developing. They provide cross-platform installers for an application that have automatic updates. Licensing is free if your application is open-source, but commercial products require purchasing a license. It might be overkill if your application is small, but I thought I'd still give it as one option.
另一种简单的方法是使用 cronjobs 更新脚本。
例如,您希望每周周日更新一次模块。为此,在终端中写入以下命令
然后在该文件的末尾写入以下行。
上述行将在周日 00:00 自动再次安装该模块。
注意:这仅适用于 Linux 或 Ubuntu。
Another easy way is to update the script using cronjobs.
For example, you want to update the module once a week on Sunday. So for this purpose, write the following command in the terminal
Then write the following line at the end of this file.
The above line will again install the module at 00:00 on Sunday automatically.
Note: This will only work on Linux or Ubuntu.