Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to upgrade a Python package on the fly?

I maintain an in-house Python package which is used by some not-really-technical people in the company. Being that their needs (or rather, their wants) change on an almost-daily basis, I have to update the library pretty often, and I create new installers for them too often for their liking.

The lib provides a high-level access to a custom in-house database. At this point, I know that I could send the lib version along with the query request, and show the user a message with the result that they need to install an update.

However, being that these people seem to think that taking a few seconds to click on an .exe file and clicking through the "next" buttons on the installer takes too long, I'm being asked to see if there's a way to automatically update the library when they do the "import X" call.

I have never come across this kind of request, and I'm thinking that if this was possible that most popular libraries would offer this option. But I've been wrong before, and often. Has anyone successfully done this before?

like image 698
badideas Avatar asked Apr 03 '13 13:04

badideas


2 Answers

I apologize if this is merely a comment.
But there are a few options available I think. And I have to agree with Cartroo, a reload() function might be sufficient.

There is a great article on this (Charming Python: Reloading on the fly) website. I am not completely sure if this is exactly what your looking for but the example in the article seems to match your needs pretty closely.

Let's paint a scenario for this article: Suppose you want to run a process on your local machine, but part of your program logic lives somewhere else. Specifically, let us assume that this program logic is updated from time to time, and when you run your process, you would like to use the most current program logic. There are a number of approaches to addressing the requirement just described; this article walks you through several of them.

like image 104
Ben Z. Avatar answered Nov 08 '22 12:11

Ben Z.


Have the "import X" call run a code in a wrapper library. The code the time of import would check the database for a new version of the library and download if it has changed. Then it can in turn import the downloaded library or import the existing library. There may be issues with this on frozen code so you might have to explicitly eval the new module.

Edit: This does not necessarily need to be done in another module. It could just be a function call.

like image 20
Demolishun Avatar answered Nov 08 '22 10:11

Demolishun