importscikit-learnjuliapycall

Why julia consume time for importing after they already give me an output?


I am studying deep learning with julia, and wrote these code.

using LinearAlgebra
using Plots
using Flux.Data
using PyCall
@pyimport pickle
@pyimport numpy as np
using ScikitLearn
@sk_import datasets: fetch_openml
println("import fin")

And I get these outputs.

┌ Warning: `@pyimport foo` is deprecated in favor of `foo = pyimport("foo")`.
│   caller = _pywrap_pyimport(::PyObject) at PyCall.jl:399
└ @ PyCall C:\Users\Username\.julia\packages\PyCall\zqDXB\src\PyCall.jl:399
import fin

But it consumes more time after I get finish sign. I ran some codes nothing special at the next script.

function AND(x1,x2)
    x = [x1 x2]
    w = [0.5 0.5]       # w1 = w2 ≤ theta
    b = -0.6
    tmp = dot(x,w) + b
    if tmp <= 0
        return 0
    elseif tmp > 0             # 0.5를 넘으면 1, 못넘으면 0 반환
        return 1
    end
end

not only codes, but markdown docs also needs time for run after importing. What causes this problem?


Solution

  • There are two issues in your question:

    1. You should be importing python modules as:

      using PyCall
      pickle = pyimport("pickle")
      np = pyimport("numpy")
      
    2. After importing a module in Julia it is being pre-compiled and hence it takes time. If you want to avoid the pre-compilation you need to build your own custom Julia image.