Skip to content

How to include source written in julia ? #202

@terasakisatoshi

Description

@terasakisatoshi

When we would like to use 3rd party library from Python via pyjulia
e.g. Images which is a Julia Package , we only have to use Main.using

from julia import Main
Main.using("Images")
img = Main.eval('load("path/to/img")') # where load is a function defined in Images package

On the other hand, is there any way import or incluide our own source code ?

For example I created a trivial example:

#example.jl
function echomsg(msg)
    return msg 
end

Then I would like to call echomsg defined above from Python.
I tried to from julia import Main; Main.eval('include("example.jl")') on python REPL
but failed with the following message

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/terasakisatoshi/.pyenv/versions/miniconda3-3.19.0/lib/python3.5/site-packages/julia/core.py", line 739, in eval
    ans = self._call(src)
  File "/Users/terasakisatoshi/.pyenv/versions/miniconda3-3.19.0/lib/python3.5/site-packages/julia/core.py", line 672, in _call
    self.check_exception(src)
  File "/Users/terasakisatoshi/.pyenv/versions/miniconda3-3.19.0/lib/python3.5/site-packages/julia/core.py", line 722, in check_exception
    .format(exception, src))
julia.core.JuliaError: Exception 'UndefVarError: include not defined' occurred while calling julia code:
include("example.jl")

How should I do ???

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions