How do you view available packages?
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
-
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
andpkgutil
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)) show_acceptable_modules()
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 possiblesetuptools
,pip
,ensurepip
andeasy_install
are missing, so installing external packages requires additional workmultiprocessing
is missing
2