pyjulia
pyjulia copied to clipboard
Exception when trying to acces submodules of Main
I was trying to explore what Python functions are available as submodules of Main, especially the PyCall module, but apparently that isn't possible? Or is this a bug?
Python 3.8.5 (default, Jul 27 2020, 08:42:51)
[GCC 10.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from julia.api import Julia
>>> j=Julia()
>>> from julia import Main
>>> dir(Main)
['Base', 'Core', 'PyCall', '__doc__', '__loader__', '__name__', '__package__', '__spec__', '_julia']
>>> dir(Main.Base)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/melis/.local/lib/python3.8/site-packages/julia/core.py", line 176, in __getattr__
return self.__try_getattr(name)
File "/home/melis/.local/lib/python3.8/site-packages/julia/core.py", line 191, in __try_getattr
if self._julia.isdefined(realname):
File "/home/melis/.local/lib/python3.8/site-packages/julia/core.py", line 645, in isdefined
raise ValueError(
ValueError: `julia.isdefined(name)` requires at least one dot in `name`.
>>>
Yes, it's a bug.
Any updates on this? Currently running into the same issue :confused:
EDIT: I'm just getting an AttributeError though. But I'm struggling to produce a MWE so it might be an interaction with the package that I want to use rather than a general issue of "submodules does't work". I gotta do some more debugging.
EDIT 2: Nvm! I'm using packages which are using Requires.jl, and it seems like it's causes some issues when starting Julia with --compiled_modules=no. When doing
import julia
jl = julia.Julia(compiled_modules=False)
from julia import Pkg
Pkg.activate("/path/to/MyPackage")
from julia import MyPackage
it wouldn't tell me that there was an error for some reason, but when I did
import julia
jl = julia.Julia(compiled_modules=False)
from julia import Pkg
Pkg.activate("/path/to/MyPackage")
from julia import Main
Main.eval("using MyPackage")
an error was thrown (and this is the same error as I get if I try to do using MyPackage from julia --compiled-modules=no).
After taking the approach using pyenv outlined in the docs, everything works!:) Thanks! Awesome package btw!