Using PythonCall, suppose I would like to import a Python module foo
and its sub-module bar
, where bar
defines baz
, I would expect the following to work but it does not:
using PythonCall
foo = pyimport("foo")
foo.bar.baz
foo.bar
is a Python module (a Py
object), but it does not have baz
defined - it doesn't seem to have any names defined.
Current workaround seems to be something like:
using PythonCall
foo = pyimport("foo")
foo_bar = pyimport("foo.bar")
foo_bar.baz
julia> using PythonCall
julia> fo = pyimport("fiftyone")
Python module: <module 'fiftyone' from '/Users/jsa/work/julia/FiftyOne.jl/.CondaPkg/env/lib/python3.11/site-packages/fiftyone/__init__.py'>
julia> fo.core
Python module: <module 'fiftyone.core' from '/Users/jsa/work/julia/FiftyOne.jl/.CondaPkg/env/lib/python3.11/site-packages/fiftyone/core/__init__.py'>
julia> fo.core.
No names defined in fo.core
, i.e. no completions available in the REPL.
Whereas all the names are defined if importing fiftyone.core
separately:
julia> fo_core = pyimport("fiftyone.core")
Python module: <module 'fiftyone.core' from '/Users/jsa/work/julia/FiftyOne.jl/.CondaPkg/env/lib/python3.11/site-packages/fiftyone/core/__init__.py'>
julia> fo_core
Python module: <module 'fiftyone.core' from '/Users/jsa/work/julia/FiftyOne.jl/.CondaPkg/env/lib/python3.11/site-packages/fiftyone/core/__init__.py'>
julia> fo_core.
__annotations__ __cached__ __class__ __delattr__ __dict__ __dir__ __doc__ __eq__ __file__ __format__
__ge__ __getattribute__ __getstate__ __gt__ __hash__ __init__ __init_subclass__ __le__ __loader__ __lt__
__name__ __ne__ __new__ __package__ __path__ __reduce__ __reduce_ex__ __repr__ __setattr__ __sizeof__
__spec__ __str__ __subclasshook__ aggregations annotation brain clips collections config context
dataset document evaluation expressions fields frame frame_utils groups json labels
logging media metadata models odm patches plots runs sample service
session singletons spaces stages state uid utils validation video view
Seems like the names are indeed there - they are returned by getpropertynames(fo.core)
- just that they somehow are not available from the REPL...
Jesper Stemann Andersen has marked this topic as resolved.
Last updated: Nov 22 2024 at 04:41 UTC