gpt4 book ai didi

python - 我无法从 Python 调用 Julia

转载 作者:行者123 更新时间:2023-12-04 08:29:33 25 4
gpt4 key购买 nike

我安装了 Julia 以从 Python (Anaconda) 调用。当我尝试调用 PyJulia 时,出现此错误并且我不确定如何修复它:

Python 3.8.3 (default, Jul  2 2020, 17:30:36) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from julia.api import Julia
>>> jl = Julia(compiled_modules=False)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Andrea\AppData\Roaming\Python\Python38\site-packages\julia\core.py", line 468, in __init__
jlinfo = JuliaInfo.load(runtime)
File "C:\Users\Andrea\AppData\Roaming\Python\Python38\site-packages\julia\juliainfo.py", line 68, in load
proc = subprocess.Popen(
File "C:\Users\Andrea\anaconda3\lib\subprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\Andrea\anaconda3\lib\subprocess.py", line 1307, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified

最佳答案

这可能有帮助:

# IMPORT JULIA
from julia.api import Julia
jpath = "julia-1.3.1/bin/julia" # path to Julia, from current directory (your path may be slightly different)
jl = Julia(runtime=jpath, compiled_modules=False) # compiled_modules=True may work for you; it didn't for me


# IMPORT JULIA MODULES
from julia import Main
Main.include("path/to/some_julia_file.jl")
jl.eval("using .some_julia_module") # use a module from some_julia_file.jl


# EVALUATE STUFF
this_equals_three = jl.eval("1+2")

# eval works with Python f-strings, so you can easily use python variables
a = 1
b = 2
also_three = jl.eval(f"{a}+{b}")

result = jl.eval(f"myfunc({a},{b})") # call custom functions imported from some_julia_file.jl

from julia import Base
equals_one = Base.sind(90)

注意:我假设您使用 pip install julia 安装了 PyJulia 包,并且您还从 julialang.org 单独安装了 Julia 语言。

关于python - 我无法从 Python 调用 Julia,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65090868/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com