julia - 将 Python sympy 模块导入 Julia

我有一个 Julia 模块,我想在其中 import Python 函数 sympy.physics.wigner.wigner_9j。我的最小示例模块如下:

module my_module

using PyCall
using SymPy
export test

test()=sympy.physics.wigner.wigner_9j(1,1,1,1,1,1,1,1,1)

end

然后在我的 Julia 笔记本中运行:

using my_module
test()

KeyError: key :physics not found

但是添加到笔记本

@pyimport sympy.physics.wigner as sympy_wigner
sympy_wigner.wigner_9j(1,1,1,1,1,1,1,1,1)

给出正确的输出。出于某种原因,在模块中使用 @pyimport 会产生错误,我通常会通过在模块中使用 __init__ 来避免这种情况,例如添加到 my_module.jl

const camb=PyNULL()

function __init__() # this should probably go in SFBBispectrum.jl
    copy!(camb, pyimport_conda("camb", "camb", "conda-forge"))
    pars=camb.CAMBparams()
end

这允许我访问 camb.CAMBparams。不幸的是,我没有为 sympy.physics.wigner.wigner_9j 做类似的事情。

回答1

已经有一段时间了,但这有帮助 https://github.com/JuliaPy/SymPy.jl/blob/master/src/physics.jl

相似文章

随机推荐

最新文章