JuliaPy / PyCall.jl

Package to call Python functions from the Julia language
MIT License
1.45k stars 186 forks source link

python package plugins #1026

Closed briochemc closed 1 year ago

briochemc commented 1 year ago

How does one import plugins that add functionality to a package?

I'm not too familiar with Python so unsure what I'm doing or I'm even using the right terminology but I'll try to explain. I am trying to install the intake-esm plugin from the intake package. I start with

using PyCall
intake = pyimport_conda("intake", "intake", "conda-forge")

and then attempt things like:

intake_esm = pyimport_conda("intake-esm", "intake-esm", "conda-forge")

which seems to install the intake-esm plugin:

julia> Conda.list()
[ Info: Running `conda list` in root environment
# packages in environment at /Users/benoitpasquier/.julia/conda/3:
#
# Name                    Version                   Build  Channel
⋮
intake                    0.6.6              pyhd8ed1ab_0    conda-forge
intake-esm                2022.9.18          pyhd8ed1ab_0    conda-forge

but throws an error (pasted below) and does not allow me to access the new functions that the intake-esm plugin is supposed to add. (In python, after importing intake and intake-esm, I should be able to do intake.open_esm_datastore(...), according to, e.g., https://github.com/intake/intake/issues/700)

What am I doing wrong? How can I access the open_esm_datastore function?


Maybe useful output from intake_esm = pyimport_conda("intake-esm", "intake-esm", "conda-forge"):

[ Info: Installing intake-esm via the Conda intake-esm package...
[ Info: Running `conda config --add channels conda-forge --file /Users/benoitpasquier/.julia/conda/3/condarc-julia.yml --force` in root environment
Warning: 'conda-forge' already in 'channels' list, moving to the top
[ Info: Running `conda install -y intake-esm` in root environment
Collecting package metadata (current_repodata.json): done
Solving environment: done

# All requested packages already installed.

ERROR: PyError (PyImport_ImportModule

⋮ # Removed instructions for brevity

) <class 'ModuleNotFoundError'>
ModuleNotFoundError("No module named 'intake-esm'")

Stacktrace:
 [1] pyimport(name::String)
   @ PyCall ~/.julia/packages/PyCall/twYvK/src/PyCall.jl:558
 [2] pyimport_conda(modulename::String, condapkg::String, channel::String)
   @ PyCall ~/.julia/packages/PyCall/twYvK/src/PyCall.jl:722
 [3] top-level scope
   @ REPL[35]:1

caused by: PyError (PyImport_ImportModule

⋮ # Removed instructions for brevity

) <class 'ModuleNotFoundError'>
ModuleNotFoundError("No module named 'intake-esm'")

Stacktrace:
 [1] pyimport(name::String)
   @ PyCall ~/.julia/packages/PyCall/twYvK/src/PyCall.jl:558
 [2] pyimport_conda(modulename::String, condapkg::String, channel::String)
   @ PyCall ~/.julia/packages/PyCall/twYvK/src/PyCall.jl:716
 [3] top-level scope
   @ REPL[35]:1
stevengj commented 1 year ago

The module name is intake, the package is intake-esm. Try

pyimport_conda("intake", "intake-esm", "conda-forge")
stevengj commented 1 year ago

I'm not too familiar with Python

This may be a difficulty, since you first need to understand how to call the module in Python before you can translate this into PyCall/Julia syntax.