Error when importing Python modules in Package namespace
- 主要言語
- Julia
- スター
- 1.5k
- フォーク
- 186
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
Hi,
I'm trying to write a standalone package that uses `PyCall`. I thought importing Python modules only once into the global namespace of the package `MyPackage` would be beneficial for performance. This works when executed in a Jupyter notebook, but not in a separate package.
Here is the code of the package `MyPackage`:
```julia
module MyPkg
using PyCall
np = pyimport("numpy")
function my_code(a)
return np.mean(a)
end
function my_code2(a)
np = pyimport("numpy")
return np.mean(a)
end
end
```
Install the package and then execute the following in a Jupyter notebook:
```julia
using MyPkg
MyPkg.my_code([1., 2.])
```
Error message:
```
ArgumentError: ref of NULL PyObject
Stacktrace:
[1] _getproperty(o::PyCall.PyObject, s::Symbol)
@ PyCall ~/.julia/packages/PyCall/ygXW2/src/PyCall.jl:299
[2] __getproperty
@ ~/.julia/packages/PyCall/ygXW2/src/PyCall.jl:312 [inlined]
[3] getproperty(o::PyCall.PyObject, s::Symbol)
@ PyCall ~/.julia/packages/PyCall/ygXW2/src/PyCall.jl:318
[4] my_code(a::Vector{Float64})
@ MyPkg ~/.julia/packages/MyPkg/3Tsby/src/MyPkg.jl:9
[5] top-level scope
@ In[3]:1
[6] eval
@ ./boot.jl:368 [inlined]
[7] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
@ Base ./loading.jl:1428
```
However, this works:
```julia
using MyPkg
MyPkg.my_code2([1., 2.])
```
This also works:
```julia
include("/MyPkg.jl")
MyPkg.my_code([1., 2.])
```
I suspect that the precompilation is somehow interfering, but I know far too little about how imports work in Julia or how `PyCall` works to be sure.
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
調査の方向性
Start with the MyPkg.jl example, PyCall's pyimport usage, and the stack trace at PyCall.jl:299-318. Reproduce the difference between MyPkg.my_code, MyPkg.my_code2, and include("/MyPkg.jl") in a Jupyter notebook, then investigate the reported precompilation behavior. Done means the package-level import works when the installed package is loaded, with a regression test covering the failing case.
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- julia, python
- 領域
- backend
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 38/100