2

In IBM's Maximo 7.6.1.1, it is possible to write automation scripts with Jython 2.7.0.

Using Jython, I want to determine what Python libraries are available in the system for import.

For instance, I can import the math and os libraries, but I can't import the json library (because it hasn't been added to the system).

  • It is not possible for me to add additional Python libraries to the system; this is locked down and is out of my control.

  • There doesn't seem to be a rhyme or reason as to which Python libraries have been included in Maximo, and which ones haven't (it doesn't seem to align with the Standard Python Library).

  • The documentation and IBM support have been of zero help.

Is there a way to determine what Python libraries are available for import -- via a Jython script?

Example: print list_of_importable_libraries()

User1974
  • 276
  • 1
  • 17
  • 63
  • 1
    What specific library do you want to add? If you want to serialize or parse JSON, you can always use this IBM package which is already included: https://www.ibm.com/support/knowledgecenter/SSEQTP_liberty/com.ibm.websphere.javadoc.liberty.doc/com.ibm.websphere.appserver.api.json_1.0-javadoc/com/ibm/json/java/package-summary.html – JPTremblay Feb 24 '20 at 16:59
  • @JPTremblay Yes, thanks. I really just want to get a list of the Python Libraries that are available -- so that I know what's there. But you're right, I can often do what I need with the Java Classes. – User1974 Feb 24 '20 at 19:56

1 Answers1

1
import pip
installed_packages = pip.get_installed_distributions()
installed_packages_list = sorted(["%s==%s" % (i.key, i.version)
     for i in installed_packages])
print(installed_packages_list)

As a (too long) one liner:

sorted(["%s==%s" % (i.key, i.version) for i in pip.get_installed_distributions()])

Possible error:

AttributeError: 'pip' has no attribute 'get_installed_distributions'

For pip == 10.0.0

You can downgrade pip to >= 9.0.0 to fix this And a possible duplicate of this quesstion.

Community
  • 1
  • 1
Umar Hayat
  • 4,300
  • 1
  • 12
  • 27
  • 1
    Does pip really come with Maximo? That seems unlikely, but interesting if it does. This answer does not acknowledge the context of IBM Maximo, which doesn't even have all of the base libraries available, which is why it is not otherwise a duplicate of the question you linked. There is good reason to believe that works there will not work here, and that should be addressed in the answer. – Dex Feb 23 '20 at 16:29
  • @Dex Bummer. I'm getting this error: `ImportError: No module named pip in – User1974 Feb 23 '20 at 16:59