How do you view available packages?

James Derrick
James Derrick Administrator, Employee Posts: 248
First Anniversary Solution Developer Community of Practice Member Ansys Employee 5 Up Votes
edited November 2022 in General Language Questions

I am new to IronPython and trying things out in Mechanical python scripting. In regular Python, you can do help('modules') to get a list of all packages that you have installed/available. E.g. you can check if numpy is installed from within the interpreter.

Is there an equivalent way to do this in IronPython? Not all the built-in packages are available and I'd like to be able to see which ones I can access within the interpreter.


Best Answer

  • Doug Addy
    Doug Addy Member, Employee Posts: 21
    First Anniversary Name Dropper First Answer Ansys Employee
    edited December 2022 Answer ✓

    This is specifically an issue with ACT, within IronPython generally you can do help('modules') as with any other version of python.

    Within ACT you can make use of shutil and pkgutil to roll your own equivalent:

    import shutil
    import pkgutil
    def show_acceptable_modules():
         line = '-' * 100
         print('{}\n{:^30}|{:^20}\n{}'.format(line, 'Module', 'Location', line))
         for entry in pkgutil.iter_modules():
             print('{:30}| {}'.format(entry[1], entry[0].path))

    Running this should give you an output similar to:

    Module Location BaseHTTPServer C:\Program Files\ANSYS Inc\v202\commonfiles\IronPython\Lib Bastion C:\Program Files\ANSYS Inc\v202\commonfiles\IronPython\Lib CGIHTTPServer C:\Program Files\ANSYS Inc\v202\commonfiles\IronPython\Lib ConfigParser C:\Program Files\ANSYS Inc\v202\commonfiles\IronPython\Lib Cookie C:\Program Files\ANSYS Inc\v202\commonfiles\IronPython\Lib DocXMLRPCServer C:\Program Files\ANSYS Inc\v202\commonfiles\IronPython\Lib ...

    It's worth highlighting that most packages in the default IronPython 2.7 distribution are present. Unfortunately there are some exceptions, mainly related to package installation and interoperability, the main exceptions are:

    • clrtype is missing, so referencing some .NET assemblies is not possible
    • setuptools, pip, ensurepip and easy_install are missing, so installing external packages requires additional work
    • multiprocessing is missing