Is it possible to write julia code in python and run it?

Viewed 122

I want to write the julia code in the .py file, and when running the py file, the julia code can also pass normally, is this possible? I am using text editor VScode, python3.10 and julia1.7.2.

Actually, I know it's a bit whimsical, but today I saw python code running successfully in julia. So I wonder if it can be reversed.

module MyModule
using PyCall
function __init__()
    py"""
    import numpy as np
    def one(x):
        return np.sin(x) ** 2 + np.cos(x) ** 2
    """
end
two(x) = py"one"(x) + py"one"(x)
end
MyModule.two(2)
2 Answers

Have a look at PyJulia.

from julia import Main
Main.eval("sin.(xs)")

JuliaCall is another possible solution.

from juliacall import Main as jl
jl.println("Hello from Julia!")
Related