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:
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:
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 packageMyPackage
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
:Install the package and then execute the following in a Jupyter notebook:
Error message:
However, this works:
This also works:
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.