using PyCall | |
# Change that to whatever packages you need. | |
const PACKAGES = ["pyyaml"] | |
# Import pip | |
try | |
@pyimport pip | |
catch | |
# If it is not found, install it | |
get_pip = joinpath(dirname(@__FILE__), "get-pip.py") | |
download("https://bootstrap.pypa.io/get-pip.py", get_pip) | |
run(`$(PyCall.python) $get_pip --user`) | |
end | |
@pyimport pip | |
args = UTF8String[] | |
if haskey(ENV, "http_proxy") | |
push!(args, "--proxy") | |
push!(args, ENV["http_proxy"]) | |
end | |
push!(args, "install") | |
push!(args, "--user") | |
append!(args, PACKAGES) | |
pip.main(args) |
This is great! Note extra @pyimport pip
is needed to work.
using PyCall
const PACKAGES = ["pyyaml"]
try
@pyimport pip
catch
get_pip = joinpath(dirname(@__FILE__), "get-pip.py")
download("https://bootstrap.pypa.io/get-pip.py", get_pip)
run(`$(PyCall.python) $get_pip --user`)
end
@pyimport pip # <<== HERE
args = UTF8String[]
if haskey(ENV, "http_proxy")
push!(args, "--proxy")
push!(args, ENV["http_proxy"])
end
push!(args, "install")
push!(args, "--user")
append!(args, PACKAGES)
pip.main(args)
Hello, how to use this file ? Is it necessary to put it somewhere and it will be automatically executed when an user install my package ?
My package depends upon a python package that is not available in conda (but it is trough pip) and I don' know where to start to guarantee its presence to users..
You need to put this file as your package deps/build.jl
file, that will be run when someone install this package.
I've tried this and the @pyimport pip
fails on Travis, it then tries to install PIP and decides it already exists. Any idea?
Calling pip.main
does not works at least as of pip v19.0.3, but probably starting around v10. See https://stackoverflow.com/questions/12332975/installing-python-module-within-code. Here's what I do instead:
import PyCall: pyimport
# See https://stackoverflow.com/questions/12332975/installing-python-module-within-code.
const PIP_PACKAGES = ["taichi", "matplotlib"]
sys = pyimport("sys")
subprocess = pyimport("subprocess")
subprocess.check_call([sys.executable, "-m", "pip", "install", "--user", "--upgrade", "--force-reinstall", PIP_PACKAGES...])
I did not checked the http_proxy part of this, so if someone know how it works, I take any needed corrections!