JuliaPy / JuliaPy/PyCall.jl

Add `pip` support in `pyimport_conda`?

Aperta
#1,028 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Julia
Stelle
1.5k
Fork
186
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

My motivation for this is using [Z3](https://github.com/Z3Prover/z3/wiki). It seems the existing wrappers for Z3[^1][^2] are stale and outdated, and at least for now, using the official Python wrappers via PyCall is a reasonable approach.

It would then be useful to be able to have it installed on demand, with `pyimport_conda`, but the official package is a [`pip` package](https://pypi.org/project/z3-solver/), so that doesn't currently work. However, Conda.jl supports `pip`.

I'm not sure one could automatically determine whether to use `pip` or not, based on the package, but … one could perhaps do something like the following? I've added a boolean keyword argument `pip`, with an associated conditional that uses `Conda.pip` instead of `Conda.add`.

```julia
function pyimport_conda(modulename::AbstractString, condapkg::AbstractString,
channel::AbstractString=""; pip::Bool=false)
try
pyimport(modulename)
catch e
if conda
@info "Installing $modulename via the $(pip ? "pip" : "Conda") $condapkg package..."
if pip
@assert isempty(channel)
Conda.pip_interop(true)
Conda.pip("install", condapkg)
else
isempty(channel) || Conda.add_channel(channel)
Conda.add(condapkg)
end
pyimport(modulename)
else

end
end
end
```

If this is a reasonable way of doing this, I'd be happy to make a PR. (Or feel free to use/adapt the suggestion above, for that matter.) Or perhaps there is some other way of achieving the same result?






[^1]: https://github.com/zenna/Z3.jl
[^2]: https://github.com/ahumenberger/Z3.jl

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

Start at the existing `pyimport_conda` entry point and inspect how it currently calls `Conda.add` and handles channels. Review the proposed `pip` option alongside `Conda.pip_interop` and `Conda.pip`; done means a pip-installed package such as `z3-solver` can be installed on demand and then imported successfully.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
julia, python
Ambito
developer-experience
Tipo di issue
Funzionalità
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
38/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.