On 10/02/20 4:46 AM, J A wrote:
as a sysadmin I've written several small tools as python command line apps
that get installed with python setup.py install. I would now like to create
another tool that would quickly list out all of my custom tools that may be
installed on the system. so that others can get a quick menu of what
commands are available. I believe I have a working app that uses the
iter_modules function to list out all of the names and then I just filter
based on names that I know to be mine.

My problem.. This works if everyone of my tools is only written in python 3
or 2, but not both. Are there any tricks to getting iter_modules to return
both python 3 and 2 installed modules?


Is the issue with iter_modules?

Remember that different Python versions are installed with separate libraries/paths. Accordingly, this lap-top's /usr/lib64 has both python2.7/ and python3.7/ sub-directories.

When an application is running under one* or the other, the sys.path changes accordingly (assuming the pkgutil.iter_modules(path=None) option).

(in case needed) Remember also that different installation methods may install packages in different directories anyway, eg personal installation or system-wide. So, even 'this' sys.path may not reveal what is present on 'this system'.

Might it be worth reversing the strategy and starting from a list of your modules, search likely portions of the directory-structure for 'your stuff'?
(from a perspective of complete ignorance of the problem domain)

* requisite notice about not using deprecated Python2.n these days!
("Do as I say, but not as I do"? I suspect/hope that this system's 2.7 is 'legacy' and no longer used for anything, including the OpSys)
--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to