Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using seval in a new module created from Python #170

Closed
dingraha opened this issue May 10, 2022 · 3 comments
Closed

Using seval in a new module created from Python #170

dingraha opened this issue May 10, 2022 · 3 comments
Labels
bug Something isn't working priority Should be fixed or implemented soon

Comments

@dingraha
Copy link
Contributor

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]>
@cjdoris cjdoris added bug Something isn't working priority Should be fixed or implemented soon labels May 10, 2022
@cjdoris
Copy link
Collaborator

cjdoris commented May 10, 2022

Ah thanks yeah that's a bug. Easy to fix, but just use juliacall.Base for now.

@cjdoris
Copy link
Collaborator

cjdoris commented May 21, 2022

Fixed on main, will be in the next release.

@cjdoris cjdoris closed this as completed May 21, 2022
@dingraha
Copy link
Contributor Author

Works great for me, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority Should be fixed or implemented soon
Projects
None yet
Development

No branches or pull requests

2 participants