diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 990f970..8337a58 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,7 @@ on: env: PYTHON: Conda - LD_LIBRARY_PATH: $LD_LIBRARY_PATH:$HOME/.julia/conda/3/lib + LD_LIBRARY_PATH: /home/runner/.julia/conda/3/x86_64/lib # used by linux os only jobs: test: @@ -36,6 +36,9 @@ jobs: arch: ${{ matrix.julia-arch }} - uses: julia-actions/cache@v1 # https://github.com/julia-actions/cache - uses: julia-actions/julia-buildpkg@latest + - name: "Export LD_LIBRARY_PATH envrioment variable" + if: ${{matrix.os == 'ubuntu-latest' && matrix.julia-version == '1.6'}} + run: export LD_LIBRARY_PATH=$LD_LIBRARY_PATH - uses: julia-actions/julia-runtest@latest - uses: julia-actions/julia-uploadcodecov@v0.1 continue-on-error: true diff --git a/Project.toml b/Project.toml index 9a5b236..140fa18 100644 --- a/Project.toml +++ b/Project.toml @@ -21,7 +21,7 @@ VersionParsing = "81def892-9a0e-5fdd-b105-ffc91e053289" [compat] Compat = "2.2, 3, 4" -Conda = "1.5.2, 1.6, 1.7" +Conda = "1.8" DataFrames = "0.20, 0.21, 0.22, 1" IterTools = "1.2, 1.3" MacroTools = "0.5" diff --git a/README.md b/README.md index 7757efd..b59b8b9 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,15 @@ To install ScikitLearn.jl, type `]add ScikitLearn` at the REPL. To import Python models (optional), ScikitLearn.jl requires [the scikit-learn Python library](https://cstjean.github.io/ScikitLearn.jl/dev/man/models/#Installation-and-importing-Python-models-1), which will be installed automatically when needed. Most of the examples use [PyPlot.jl](https://github.com/stevengj/PyPlot.jl) +## Known issue + +On Linux builds, importing python models via `@sk_import` is known to fail for Julia v<0.8.4 when the `PYTHON` enviroment variable from `PyCall.jl` is set to `""` or `conda`. This is becuase the version libstdcxx loaded by Julia v<0.8.4 isn't compatible with the version of scikit-learn installed via Conda. +The easiest and recommended way to resolve this is to upgrade to Julia v>=1.8.4. If you must stick with your current julia version you can also resolve this issue by pre-appending your system's `LD_LIBRARY_PATH` enviroment variable as shown below +```bash +ROOT_ENV=`julia -e "using Conda; print(Conda.ROOTENV)` +export LD_LIBRARY_PATH=$ROOT_ENV"/lib":$LD_LIBRARY_PATH +``` + ## Documentation See the [manual](https://cstjean.github.io/ScikitLearn.jl/dev/) and diff --git a/src/Skcore.jl b/src/Skcore.jl index 829701f..950f8d9 100644 --- a/src/Skcore.jl +++ b/src/Skcore.jl @@ -166,55 +166,74 @@ function import_sklearn() global mkl_checked global libstdcxx_solved - @static if Sys.isapple() - mod = try + mod = try + @static if Sys.isapple() if PyCall.conda && !mkl_checked try # check for existence of mkl-service. # Numpy, sklearn, etc. requires either `mkl` or `no-mkl` service to run # By default Conda comes with mkl - # For this package to run on MacOS the `no-mkl` versions of Numpy, sklearn is needed - pyimport("mkl") + # For this package to run on MacOS, the `no-mkl` versions of Numpy, sklearn are needed + pyimport("mkl") # jumps to catch block if "mkl" doesn't exist on the users Mac - #following Code runs only if mkl-service exists otherwise jumps to catch branch - @info "Installing non-mkl versions of sci-kit learn via Conda" - #use non-mkl versions of python packages when ENV["PYTHON"]="Conda" or "" is used - #when a different non-conda local python is used everthing works fine + # following Code runs only if mkl-service exists otherwise jumps to catch branch + @info( + "Uninstalling mkl and Installing "* + "non-mkl versions of sci-kit learn via Conda" + ) + # Use non-mkl versions of python packages when ENV["PYTHON"]="Conda" + # or "" is used. + # When a different non-conda local python is used everthing works fine Conda.add("nomkl") Conda.rm("mkl")#This also removes mkl-service - #force reinstall of scikit-learn replacing any previous mkl version - Conda.add("scikit-learn") - Conda.add("openblas") - Conda.add("llvm-openmp", channel = "conda-forge") - mkl_checked = true - catch - mkl_checked = true - end + catch err + ## This block is reached when `mkl` pkg isn't installed. + @info( + "mkl not found, proceeding to installing non-mkl versions "* + "of sci-kit learn via Conda" + ) + end + # force reinstall of scikit-learn replacing any previous mkl version + Conda.add("scikit-learn>=1.2,<1.3", channel="conda-forge") + #Conda.add("openblas") + #Conda.add("llvm-openmp", channel = "conda-forge") + mkl_checked = true + end + #PyCall.pyimport_conda("sklearn", "scikit-learn>=1.2,<1.3", "conda-forge") + else + @static if Sys.islinux() + if !libstdcxx_solved + version = _compatible_libstdcxx_ng_version() + Conda.add("conda", channel="anaconda") + Conda.add("libstdcxx-ng$version", channel="conda-forge") + #= + if version == ">=3.4,<12.0" + # https://github.com/scikit-learn/scikit-learn/pull/23990 + Conda.add("scikit-learn>=1.2,<1.3", channel="conda-forge") + end + =# + libstdcxx_solved = true + end end - Conda.add("llvm-openmp", channel = "conda-forge") - PyCall.pyimport_conda("sklearn", "scikit-learn") - - catch - @info("scikit-learn isn't properly installed."* - "Please use PyCall default Conda or non-conda local python") - rethrow() end - - elseif Sys.islinux() - if !libstdcxx_solved - version = _compatible_libstdcxx_ng_version() - Conda.add("conda", channel="anaconda") - Conda.add("libstdcxx-ng$version", channel="conda-forge") - if version == ">=3.4,<12.0" - # https://github.com/scikit-learn/scikit-learn/pull/23990 - Conda.add("scikit-learn<1.1", channel="conda-forge") + PyCall.pyimport_conda("sklearn", "scikit-learn>=1.2,<1.3", "conda-forge") + catch + INFO_MSG = "scikit-learn isn't properly installed."* + "Please make sure PyCall is using the default Conda or non-conda local python." + @static if Sys.islinux() + if libstdcxx_solved + INFO_MSG = INFO_MSG * + "\nIf you are experiencing Conda package conflicts, this may "* + "be because the version libstdcxx loaded by Julia $(Base.VERSION) "* + "isn't compatible with the version of scikit-learn installed by "* + "Conda. To resolve this, we recommend upgrading to Julia v>=1.8.4.\n"* + "If you must stick with your current julia version you can "* + "also resolve this issue by pre-appending `$(CONDA.ROOTENV)/lib` to "* + "your system's `LD_LIBRARY_PATH` enviroment variable." end - libstdcxx_solved = true end - - mod = PyCall.pyimport_conda("sklearn", "scikit-learn") - else - mod = PyCall.pyimport_conda("sklearn", "scikit-learn") + @info(INFO_MSG) + rethrow() end version = VersionParsing.vparse(mod.__version__)