I’m working on my first package ever in any language. I want to eventually turn this package into an standalone app (using PackageCompiler.jl). I am running into some trouble.
My (local) package MyPackage
uses a python package PyPackage
. I’ve pip-installed PyPackage
using Conda.jl
, and am using PyCall.jl
to use it. I use PyPackage
functionality to define my own struct S
, and later to do some processing on instances of S
. The contents of MyPackage/src/MyPackage.jl
look something like what I’ve shown below.
When I run this file alone, all goes well, and I am able to define instances of S
and use my_func
.
When I do using MyPackage
, I get errors. For instance, when I do S()
, I get a complaint from somewhere in .julia/packages/PyCall
that py_f()
is not defined.
I believe this is an issue with how my environment is setup, and possibly a limitation of PyCall.
I suspect that when I eventually turn the package into an app, I will need Python, PyCall, MyPackage, and PyPackage all to be working in/from the same environment. But Conda.jl
’s documentation states that “If you are installing Python packages for use with PyCall, you must use the root environment.”
Currently, PyCall seems to be running from .julia/packages
, even though I have added it to MyPackage’s Project.toml as a dependency.
My questions:
-
Is my understanding correct that Python, PyCall, MyPackage, and PyPackage all will need to be working in/from the same environment for me to ultimately turn MyPackage into an app?
-
If yes, does it mean that PyCall.jl + Conda.jl combination can not achieve this? I prefer PyCall because of the
py""
syntax. -
If I have to switch to PythonCall.jl + CondaPkg.jl, how would I re-do this? (If you could kindly show me by re-work the toy code below.)
(If you respond, just know that I might need to come back to this post tomorrow.)
module MyPackage
ENV["PythonPackage_API_KEY"] = "xxx" # need to set before `using PyCall`
using PyCall
jl_func(x) = # a function that does some processing
py"""
from PyPackage import py_f, py_g, py_h
"""
struct S
a
function S()
a = jl_func(py"py_f()") # -----> python
return new(a)
end
end
function my_func(s::S)
py"""
x = py_g($s.a) # -----> python
"""
result = py"py_h(x)" # -----> python
return result
end
end # end of module