Julia 1.1.0中使用pyimport的问题

Julia 1.1.0中使用pyimport的问题,julia,Julia,我制作了一个模块,在核心数量上有一个if条件 module mymodule import Pkg import PyCall using Distributed if nworkers() > 1 @everywhere using Pkg @everywhere Pkg.activate(".") @everywhere Pkg.instantiate() @everywhere using PyCall @everywhere @pyim

我制作了一个模块,在核心数量上有一个if条件

module mymodule

import Pkg
import PyCall

using Distributed

if nworkers() > 1
    @everywhere using Pkg
    @everywhere Pkg.activate(".")
    @everywhere Pkg.instantiate()
    @everywhere using PyCall
    @everywhere @pyimport scipy.signal as ss

    function parallel()
          ....
    end

else
    using Pkg
    Pkg.activate(".")
    Pkg.instantiate()
    using PyCall
    @pyimport scipy.signal as ss
    function serial()
    ....
    end
end
end #mymodule

代码在执行时抛出以下错误

ERROR: LoadError: LoadError: UndefVarError: @pyimport not defined
Stacktrace:
 [1] top-level scope
 [2] include at ./boot.jl:326 [inlined]
 [3] include_relative(::Module, ::String) at ./loading.jl:1038
 [4] include(::Module, ::String) at ./sysimg.jl:29
 [5] include(::String) at ./client.jl:403
 [6] top-level scope at none:0
in expression starting at /storage/work/s/mymodule.jl:81
in expression starting at /storage/work/s/mymodule.jl:30
其中,第81行是else条件下对应于
@pyimport scipy.signal as ss
的行,第30行对应于
if nworkers()>1

在出现此问题之前,代码中的行
@everywhere@pyimport scipy.signal作为ss
存在问题,但通过使用
import PyCall
,该问题消失了;奇怪的是,它并没有解决前一个问题


是否有人经历过类似问题或意识到此类问题

您需要改用
pyimport
函数。宏定义(来自使用的
),由于解析/求值顺序,在同一块中使用该宏不起作用

只需更改代码即可

@pyimport scipy.signal as ss

您还可以将块分为两部分,第一部分用于定义,第二部分用于使用。但是,我不会作为
@pyimport
宏那样做

ss = pyimport("scipy.signal")