Add `pip` support in `pyimport_conda`?
- Dominant language
- Julia
- Stars
- 1.5k
- Forks
- 186
- PR merge metrics
- No merged PRs in 30d
Description
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
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.