-
Notifications
You must be signed in to change notification settings - Fork 67
Example python package using juliacall #49
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
Comments
Possibly related: I was just looking into trying to make a combined python-julia project (with the python and julia code in the same git repository, and neither are published). Any ideas for how this should work? I've got an example where I manually modify the "juliacalldeps.json" file in a build step, but is there something smarter that could be done? |
What exactly does the build step do? I imagine you need to refer to the directory of the package. I've been thinking about adding some templating so that |
Ok, to make this easier I thought I'd actually publish an example (and also contribute to this issue a little more directly). You can see what I'm currently doing here https://github.com/msundvick/ffi_examples. Specifically, the relevant build step is in with open("juliacalldeps.json", "r") as f:
jl = json.load(f)
jl["packages"]["FfiExamples"]["path"] = os.getcwd()
with open("juliacalldeps.json", "w") as f:
json.dump(jl, f)
import juliacall As for whether Edit: I've tried to strip it down a bit; there's a bunch of other stuff in that repo: https://github.com/msundvick/ffi_examples/tree/just-julia. |
Oh right yeah, the |
I've fixed the relative paths issue on the master branch. |
I'm also expecting an example python package that uses JuliaCall, i.e. a demonstration of Python wrapper over a Julia package.
Maybe I can also help on these as well. |
There is no Instead, JuliaCall takes advantage of multiple inheritance so that a Julia Dict is wrapped as a DictValue, which is both an AnyValue (i.e. a Julia object) and a Mapping (i.e. behaves like a Python dict). If you want an actual Python dict you can do This system can be extended by defining new subtypes of It would be great if you could contribute an example package. |
I learn something more! So here is a situation where I want to pass a Julia object (currently shown as struct MyType
name::String
dir::String
fid::IOStream
variable::Vector{String}
#...
end
function load(...)
# some operations...
return MyType(...)
end and in Python from juliacall import Main as jl
jl.seval("using MyPkg")
file = "example_file_name"
meta = jl.load(file) # <class 'juliacall.AnyValue'>, shown by type(meta) Now I may need some Python functions which operates on this Julia type def plot(meta: MyType):
var = jl.readvariable(meta, "myvar")
x = np.arange(meta.coordmin[0], meta.coordmax[0], meta.dcoord[0])
plt.plot(x, var)
plt.show() Without the type annotation in Python, this can work, since all the methods for meta lives in the Julia package which understands
If you can quickly provide a concrete example of how to do this, I think I may easily come up with a Python interface for my data processing package that uses Matplotlib for plotting 😄 . |
I'd be great to have some example(s) on this. I started with a very basic repo, but still I have difficulties. Maybe someone here has a good idea? https://github.com/fzeiser/juliacall_test I have a very simple routine I want to call in julia from python: module Foo
export foo
using PythonCall
function foo(a)
println(typeof(a))
b = pyconvert(Array, a)
println(typeof(b))
end
end If I try to call this script with I think that it would be nice to have some basic examples of this kind. and of course -- any help on my particular example is appreciated :). The issue with
[I tried to add a |
Big surprise for me: I got it working -- but I'm not sure what the general message of this should be / what I did wrong in the first place. I added a
. I then tried to run the same commands as juliapkg seemingly tries to run in the terminal
Suddenly, now I can run
Maybe someone can try to reproduce this? Maybe it was just a confusion on my side due to the environments? Still, I think the error message was not quite telling... |
No description provided.
The text was updated successfully, but these errors were encountered: