我试图在一些Python代码中包含Julia函数(PowerModelsDistribution.solve_mc_opf)。这个包在Julia中工作,但我被困在PyJulia中。我尝试了一些方法:
1。
from julia import Pkg
Pkg.activate("C:/Users/Aisling/.julia/environments/pmd") # pmd is my Julia env but I've also tried this in my base
from julia.PowerModelsDistribution import solve_mc_opf
在
搜索结果
ImportError Traceback (most recent call last)
<ipython-input-33-6e83bbbb609c> in <module>
----> 1 from julia.PowerModelsDistribution import solve_mc_opf
C:ProgramDataAnaconda3libsite-packagesjuliacore.py in load_module(self, fullname)
258 JuliaModule(self, fullname))
259
--> 260 raise ImportError("{} not found".format(juliapath))
261
262
ImportError: PowerModelsDistribution.solve_mc_opf not found
- 然后我试着:
import julia
jl = julia.Julia()
res = jl.run(PowerModelsDistribution.solve_mc_opf("documents/powermodelsdistribution/test/data/opendss/case3_unbalanced.dss", ACPUPowerModel, Ipopt.Optimizer))
结果:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-29-2af5367df821> in <module>
----> 1 res = jl.run(PowerModelsDistribution.solve_mc_opf("documents/powermodelsdistribution/test/data/opendss/case3_unbalanced.dss", ACPUPowerModel, Ipopt.Optimizer))
C:ProgramDataAnaconda3libsite-packagesjuliacore.py in __getattr__(self, name)
174 def __getattr__(self, name):
175 try:
--> 176 return self.__try_getattr(name)
177 except AttributeError:
178 if name.endswith("_b"):
C:ProgramDataAnaconda3libsite-packagesjuliacore.py in __try_getattr(self, name)
197 return self._julia.eval(jl_fullname)
198
--> 199 raise AttributeError(name)
200
201
AttributeError: solve_mc_opf
我难住了。
我想你应该这样做:
from julia import PowerModelsDistribution
PowerModelsDistribution.solve_mc_opf("...")
所以你应该导入一个Julia模块到Python而不是函数。