简体   繁体   English

如何将 Julia 包导入 Python

[英]How to import Julia packages into Python

One can use Julia's built-in modules and functions using the juliacall package.可以使用juliacall包使用 Julia 的内置模块和函数。 for example:例如:

>>> from juliacall import Main as jl
>>> import numpy as np

# Create a 2*2 random matrix
>>> arr = jl.rand(2,2)

>>> arr
<jl [0.28133223988783074 0.22498491616860727; 0.008312971104033062 0.12927167014532326]>

# Check whether Numpy can recognize the shape of the array or not
>>> np.array(arr).shape
(2, 2)

>>> type(np.array(arr))
<class 'numpy.ndarray'>

Then I'm curious to know if importing an installed julia package into Python is possible?然后我很想知道是否可以将已安装的 julia 包导入 Python? For example, let's say that one wants to import Flux.jl into Python.例如,假设有人想将Flux.jl导入 Python。 Is there a way to achieve this?有没有办法做到这一点?

I found it through scrutinizing the pictures of the second example of the juliacall GitHub page.我是通过juliacall GitHub 页面的第二个示例的图片找到的。 According to the example, I'm able to import Flux.jl by taking these steps:根据示例,我可以通过以下步骤导入Flux.jl

>>> from juliacall import Main as jl
>>> jl.seval("using Flux")

Also, one can install any registered Julia package using Pkg in Python:此外,可以在 Python 中使用Pkg安装任何已注册的 Julia 包:

>>> from juliacall import Main as jl
>>> jl.Pkg.add("Flux")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM