pyjulia icon indicating copy to clipboard operation
pyjulia copied to clipboard

can not load a julia module inside a julia module

Open Roger-luo opened this issue 6 years ago • 4 comments

I'm not sure what is causing this, but when I try (after install Yao#master and PyCall)

from julia.Yao import *

it gives me

~/miniconda3/lib/python3.7/site-packages/julia/core.py in __getattr__(self, name)
    167     def __getattr__(self, name):
    168         try:
--> 169             return self.__try_getattr(name)
    170         except AttributeError:
    171             if name.endswith("_b"):

~/miniconda3/lib/python3.7/site-packages/julia/core.py in __try_getattr(self, name)
    182         if self._julia.isamodule(jl_fullname):
    183             realname = self._julia.fullname(self._julia.eval(jl_fullname))
--> 184             if self._julia.isdefined(realname):
    185                 return self.__loader__.load_module("julia." + realname)
    186             # Otherwise, it may be, e.g., "Main.anonymous", created by

~/miniconda3/lib/python3.7/site-packages/julia/core.py in isdefined(self, fullname)
    641 
    642         if isinstance(parent, string_types):
--> 643             parent = self.eval(parent)
    644         return isdefinedstr(parent, member)
    645 

~/miniconda3/lib/python3.7/site-packages/julia/core.py in eval(self, src)
    595         if src is None:
    596             return None
--> 597         ans = self._call(src)
    598         if not ans:
    599             return None

~/miniconda3/lib/python3.7/site-packages/julia/core.py in _call(self, src)
    528         # logger.debug("_call(%s)", src)
    529         ans = self.api.jl_eval_string(src.encode('utf-8'))
--> 530         self.check_exception(src)
    531 
    532         return ans

~/miniconda3/lib/python3.7/site-packages/julia/core.py in check_exception(self, src)
    578             exception = sprint(showerror, self._as_pyobj(res))
    579         raise JuliaError(u'Exception \'{}\' occurred while calling julia code:\n{}'
--> 580                          .format(exception, src))
    581 
    582     def _typeof_julia_exception_in_transit(self):

JuliaError: Exception 'UndefVarError: YaoBase not defined' occurred while calling julia code:

any idea how to fix?

Roger-luo avatar Dec 03 '19 19:12 Roger-luo

It seems this is caused by using Reexport since Yao is just a meta package these modules are reexported using Reexport, but somehow it cannot be found by python...

Roger-luo avatar Dec 04 '19 06:12 Roger-luo

Maybe some packages export names that do not exist. FYI Aqua.test_undefined_exports may be an easy way to find those names. If this is the case import julia.Yao or from julia import Yao should work.

Also, what do you see after JuliaError: Exception 'UndefVarError: YaoBase not defined' occurred while calling julia code: ?

Having said that, PyJulia shouldn't fail due to this.

tkf avatar Dec 05 '19 04:12 tkf

yeah, but sometimes I need to call Yao.YaoBase (although it is not very often, but...) then it give me the same error as above

Roger-luo avatar Dec 05 '19 08:12 Roger-luo

OK. So I tried it on my laptop. The problem is that top-level import does not work for indirect dependencies in Julia (e.g. Yao is in Project.toml but YaoBase is not). I think this should be quite straightforward to fix it now that we dropped Julia 0.6.

tkf avatar Dec 07 '19 21:12 tkf