Closed
Description
It looks like the prefered way of using
or importing a Julia module from Python is to use seval
. The docs also recommend creating a new module using the newmodule
command to avoid polluting the Main namespace. But when I try to do anything with seval and a new module, I get an error saying that eval
doesn't exist in the new module. It appears that newmodule
creates a baremodule
. Is this expected?
Here's an example:
import juliacall; jl = juliacall.newmodule("Foo")
# import juliacall; jl = juliacall.Main
print(jl.seval("1 + 2"))
The error I get:
(venv) dingraha@GRLRL2021060743 ~/p/p/test3> python simple_seval.py
[juliapkg] Locating Julia ^1.6
[juliapkg] Using Julia 1.7.2 at /home/dingraha/.gpfx/home/dingraha/local/julia/1.7.2/bin/julia
[juliapkg] Using Julia project at /home/dingraha/projects/pythoncall_openmdao
[juliapkg] Installing packages:
julia> import Pkg
julia> Pkg.add([Pkg.PackageSpec(name="PythonCall", uuid="6099a3de-0909-46bc-b1f4-468b9a2dfc0d")])
julia> Pkg.resolve()
Updating registry at `~/.julia/registries/DanielIngrahamRegistry`
Updating git-repo `[email protected]:dingraha/DanielIngrahamRegistry.git`
Updating registry at `~/.julia/registries/General.toml`
Resolving package versions...
No Changes to `~/projects/pythoncall_openmdao/Project.toml`
No Changes to `~/projects/pythoncall_openmdao/Manifest.toml`
No Changes to `~/projects/pythoncall_openmdao/Project.toml`
No Changes to `~/projects/pythoncall_openmdao/Manifest.toml`
Traceback (most recent call last):
File "/home/dingraha/projects/pythoncall_openmdao/test3/simple_seval.py", line 3, in <module>
print(jl.seval("1 + 2"))
File "/home/dingraha/.julia/packages/PythonCall/XgP8G/src/jlwrap/module.jl:19", line 7, in seval
juliacall.JuliaError: MethodError: no method matching eval(::Expr)
You may have intended to import Base.eval
Closest candidates are:
eval(!Matched::Module, !Matched::Any) at ~/.gpfx/home/dingraha/local/julia/1.7.2/share/julia/base/boot.jl:373
Stacktrace:
[1] pyjlmodule_seval(self::Module, expr::PythonCall.Py)
@ PythonCall ~/.julia/packages/PythonCall/XgP8G/src/jlwrap/module.jl:13
[2] _pyjl_callmethod(f::Any, self_::Ptr{PythonCall.C.PyObject}, args_::Ptr{PythonCall.C.PyObject}, nargs::Int64)
@ PythonCall ~/.julia/packages/PythonCall/XgP8G/src/jlwrap/base.jl:62
[3] _pyjl_callmethod(o::Ptr{PythonCall.C.PyObject}, args::Ptr{PythonCall.C.PyObject})
@ PythonCall.C ~/.julia/packages/PythonCall/XgP8G/src/cpython/jlwrap.jl:47
(venv) dingraha@GRLRL2021060743 ~/p/p/test3 [1]>