Search code examples
pythonopencvjuliapycall

I want to use OpenCV on Julia via PyCall


I want to use OpenCV on Julia, then I tried to use PyCall.
I made my Python environment by pyenv, therefore, I tried below commands;

julia> ENV["PYTHON"] = "/Users/MYNAME/.pyenv/shims/python"
julia> using Pkg
julia> Pkg.add("PyCall")

Then, I tried a below command and this error message was returned.

julia> using PyCall
ImportError: No module named site

This error message is too short to infer causes. Anyone knows the causes and how to solve?


Solution

  • PyCall is tested with Anaconda and it works best with the Anaconda installation inbuilt into Julia.

    using Pkg
    #ENV["PYTHON"] = ""
    pkg"add PyCall"
    #pkg"build PyCall"   #required to restore the default config if you changed it
    pkg"add Conda"
    using Conda
    Conda.runconda(`install -c conda-forge opencv`)
    using PyCall
    const cv = pyimport("cv2")
    

    Now you are ready to do your work.