# Imported ScikitLearn PyObj becomes NULL in a module

**URL:** <https://discourse.julialang.org/t/imported-scikitlearn-pyobj-becomes-null-in-a-module/30942>\
**Category:** General Usage\
**Tags:** question\
**Created:** [November 11, 2019, 8:08am UTC](https://discourse.julialang.org/t/imported-scikitlearn-pyobj-becomes-null-in-a-module/30942 "2019-11-11T08:08:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sijun](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@Sijun](https://discourse.julialang.org/u/Sijun)\
**Post date:** [November 11, 2019, 8:08am UTC](https://discourse.julialang.org/t/imported-scikitlearn-pyobj-becomes-null-in-a-module/30942/1 "2019-11-11T08:08:44Z")

</div>

```julia
module TestMod
using ScikitLearn: @sk_import

@sk_import linear_model: LogisticRegression

println(LogisticRegression)

export fun

function fun()
    println(LogisticRegression)
end

end

```

When the above TestMod is imported, LogisticRegressionis imported and printed:

> PyObject \<class ‘sklearn.linear\_model.logistic.LogisticRegression’\>

But after that, strangely LogisticRegression becomes NULL:

> julia\> TestMod.LogisticRegression  
> PyObject NULL

> julia\> TestMod.fun()  
> PyObject NULL

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [November 11, 2019, 12:13pm UTC](https://discourse.julialang.org/t/imported-scikitlearn-pyobj-becomes-null-in-a-module/30942/2 "2019-11-11T12:13:32Z")

</div>

Yeah that’s tricky, you need to place the import in the init function, see how I did it here  
[https://github.com/baggepinnen/HDBSCAN.jl/blob/master/src/HDBSCAN.jl](https://github.com/baggepinnen/HDBSCAN.jl/blob/master/src/HDBSCAN.jl)

---

<div class="post-metadata">

**Author:** ![Sijun](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@Sijun](https://discourse.julialang.org/u/Sijun)\
**Post date:** [November 11, 2019, 1:15pm UTC](https://discourse.julialang.org/t/imported-scikitlearn-pyobj-becomes-null-in-a-module/30942/3 "2019-11-11T13:15:46Z")

</div>

@baggepinnen, it works very well! I don’t know what to say. Thank you so much! 🙂

Here is some small questions:

1. what benefit would the use of @eval give us? On the surface, all is fine without @eval.
2. How does the trick work?

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [November 11, 2019, 2:26pm UTC](https://discourse.julialang.org/t/imported-scikitlearn-pyobj-becomes-null-in-a-module/30942/4 "2019-11-11T14:26:17Z")

</div>

You’ll find more info here  
[https://github.com/JuliaPy/PyCall.jl/blob/master/README.md#using-pycall-from-julia-modules](https://github.com/JuliaPy/PyCall.jl/blob/master/README.md#using-pycall-from-julia-modules)  
It seems there is a recommended approach slightly different from mine.

---

<div class="post-metadata">

**Author:** ![Sijun](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@Sijun](https://discourse.julialang.org/u/Sijun)\
**Post date:** [November 11, 2019, 2:39pm UTC](https://discourse.julialang.org/t/imported-scikitlearn-pyobj-becomes-null-in-a-module/30942/5 "2019-11-11T14:39:43Z")

</div>

Aha, I understood what is happening now. Thank you!
