![](/img/trans.png)
[英]Calling function from Julia file does not read image in Python file
[英]Julia Calling Python Function
我一直在嘗試使用以下代碼從Julia中調用python函數:
using PyCall
unshift!(PyVector(pyimport("sys")["path"]), "")
@pyimport testing
print(testing.add())
測試是在同一條道路上。
測試python文件:
def add():
return 5 + 5
我從朱莉婭得到這個錯誤:
LoadError: PyError (ccall(@pysym(:PyImport_ImportModule), PyPtr, (Cstring,),
name)) <class 'ImportError'> ImportError("No module named 'testing'",)
while loading C:\Users\Benjamin\AppData\Local\JuliaPro-0.6.0.1\test.jl, in expression starting on line 410
pyerr_check at exception.jl:56 [inlined]
pyerr_check at exception.jl:61 [inlined]
macro expansion at exception.jl:81 [inlined]
pyimport(::String) at PyCall.jl:370
include_string(::String, ::String) at loading.jl:515
include_string(::Module, ::String, ::String) at Compat.jl:577
(::Atom.##55#58{String,String})() at eval.jl:73
withpath(::Atom.##55#58{String,String}, ::String) at utils.jl:30
withpath(::Function, ::String) at eval.jl:38
macro expansion at eval.jl:71 [inlined]
(::Atom.##54#57{Dict{String,Any}})() at task.jl:80
我怎樣才能解決這個問題?
另外,我該怎么做:(朱莉婭):
using PyCall
unshift!(PyVector(pyimport("sys")["path"]), "")
@pyimport testing
print(testing.add(5, 5))
(蟒蛇):
def add(a, b):
return a + b
如果我將您的testing.py
文件重命名為其他名稱,例如mytests.py
,那么這對您mytests.py
julia> using PyCall
julia> unshift!(PyVector(pyimport("sys")["path"]), "")
PyObject ['', … ]
julia> @pyimport mytests
julia> mytests.add(5,5)
10
我的site-packages文件夾中有一個testing
包,這可能會引起問題:
julia> @pyimport testing
julia> testing.__path__
1-element Array{String,1}:
"/.../lib/python2.7/site-packages/testing"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.