Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to maintain different version of a python module?

Tags:

python

module

I have this core python module we use in our facility called mfxLib. I need to be able to keep different version of this module without breaking all the other modules/plugin that are importing this module.

My solution was keep a duplicate of my module by renaming them mfxLib01 and mfxLib02 then to replace the original mfxLib module with an empty module containing only a __init__.py file that import the latest version.

# content of mfxLib.__init__.py
from mfxLib02 import *

This seems logical and seems to work but I was wondering if there was a common practice for doing this? guidelines to follow? etc

Thanks

like image 435
Sylvain Berger Avatar asked Mar 26 '26 06:03

Sylvain Berger


2 Answers

You can import a module as another name. Commonly people use this to save typing in a long module name, for example:

import numpy as np
np.array([1,2,3,4])

Hence you could do:

import mfxLib01 as mfxLib

or

import mfxLib02 as mfxLib

then your code uses mfxLib everywhere.

That might help...

like image 133
Spacedman Avatar answered Mar 27 '26 21:03

Spacedman


If you have different scripts requiring different versions, your current approach should be the the best, but I'd suggest using a version control system like Git or SVN. That would allow you to commit and revert to earlier versions easily, as well as share the module with other users.

like image 21
Håvard Avatar answered Mar 27 '26 21:03

Håvard



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!