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

UndefVarError when using include in a new module #176

Closed
dingraha opened this issue May 25, 2022 · 2 comments
Closed

UndefVarError when using include in a new module #176

dingraha opened this issue May 25, 2022 · 2 comments

Comments

@dingraha
Copy link
Contributor

I'm trying to include a Julia file from a Python script. Works fine when I'm using the Main module, but not when I use juliacall.newmodule to create a new module. Here's an example:

with open("include_test.jl", "w") as f:
    print("x = 8", file=f)
# from juliacall import Main as jl
import juliacall; jl = juliacall.newmodule("IncludeTest")
jl.include("include_test.jl")
print(f"jl.x = {jl.x}")

When I try to run that, I get this:

(venv) dingraha@GRLRL2021060743 ~/p/p/include_test> python include_test.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/dev/venv/julia_env
[juliapkg] Installing packages:
           julia> import Pkg
           julia> Pkg.add([Pkg.PackageSpec(name="PythonCall", uuid="6099a3de-0909-46bc-b1f4-468b9a2dfc0d"), Pkg.PackageSpec(name="OpenMDAOCore", uuid="24d19c10-6eee-420f-95df-4537264b2753"), Pkg.PackageSpec(name="LinearAlgebra", uuid="37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
)])
           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/dev/venv/julia_env/Project.toml`
  No Changes to `~/projects/pythoncall_openmdao/dev/venv/julia_env/Manifest.toml`
  No Changes to `~/projects/pythoncall_openmdao/dev/venv/julia_env/Project.toml`
  No Changes to `~/projects/pythoncall_openmdao/dev/venv/julia_env/Manifest.toml`
Traceback (most recent call last):
  File "/home/dingraha/projects/pythoncall_openmdao/include_test/include_test.py", line 5, in <module>
    jl.include("include_test.jl")
  File "/home/dingraha/.julia/packages/PythonCall/mw9sU/src/jlwrap/any.jl", line 190, in __getattr__
    return self._jl_callmethod($(pyjl_methodnum(pyjlany_getattr)), k)
AttributeError: Julia: UndefVarError: include not defined
(venv) dingraha@GRLRL2021060743 ~/p/p/include_test [1]>
@cjdoris
Copy link
Collaborator

cjdoris commented May 27, 2022

Ahh include is no ordinary function. I've changed the way newmodule works internally and it works now. I've made a release.

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

Works great, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants