我如何在 mamba 环境中使 IJulia 正常工作?

huangapple go评论54阅读模式
英文:

How can I get IJulia working inside a mamba environment?

问题

I am having trouble installing IJulia in Julia 1.9.1 inside a mamba environment. The crux of the issue seems to be the compiler not being able to find MbedTLS even though it is installed:

Looking for: ['mbedtls']

conda-forge/noarch                                  13.1MB @   4.4MB/s  3.4s
conda-forge/linux-64                                32.7MB @   4.2MB/s  8.9s

Pinned packages:
  - python 3.11.*

Transaction

  Prefix: /shares/teacher/users/student/mambaforge/envs/jenv

  All requested packages already installed
> Using Pkg
> Pkg.update()
>Pkg.add("IJulia") # this works fine
> Using IJulia # This does not

The error when running the above commands is:

MbedTLS [739be429-bea8-5141-9913-cc70e7f3736d]

Failed to precompile MbedTLS [739be429-bea8-5141-9913-cc70e7f3736d] to "libmbedtls.so".
libmbedx509.so.4: cannot open shared object file: No such file or directory
Stacktrace:
  [1] dlopen(s::String, flags::UInt32; throw_error::Bool)
    @ Base.Libc.Libdl ./libdl.jl:117
  [2] dlopen
    @ ./libdl.jl:116 [inlined]
  [3] dlopen(s::String)
    @ Base.Libc.Libdl ./libdl.jl:116
  [4] __init__()
    @ MbedTLS_jll ~/mambaforge/envs/jenv/share/julia/stdlib/v1.9/MbedTLS_jll/src/MbedTLS_jll.jl:42
  [5] register_restored_modules(sv::Core.SimpleVector, pkg::Base.PkgId, path::String)
    @ Base ./loading.jl:1115
  [6] _include_from_serialized(pkg::Base.PkgId, path::String, ocachepath::String, depmods::Vector{Any})
    @ Base ./loading.jl:1061
  [7] _require_search_from_serialized(pkg::Base.PkgId, sourcepath::String, build_id::UInt128)
    @ Base ./loading.jl:1506
  [8] _require(pkg::Base.PkgId, env::String)
    @ Base ./loading.jl:1783
  [9] _require_prelocked(uuidkey::Base.PkgId, env::String)
    @ Base ./loading.jl:1660
 [10] macro expansion
    @ ./loading.jl:1648 [inlined]
 [11] macro expansion
    @ ./lock.jl:267 [inlined]
 [12] require(into::Module, mod::Symbol)
    @ Base ./loading.jl:1611
 [13] include
    @ ./Base.jl:457 [inlined]
 [14] include_package_for_output(pkg::Base.PkgId, input::String, depot_path::Vector{String}, dl_load_path::Vector{String}, load_path::Vector{String}, concrete_deps::Vector{Pair{Base.PkgId, UInt128}}, source::Nothing)
    @ Base ./loading.jl:2045
 [15] top-level scope
    @ stdin:3
during initialization of module MbedTLS_jll
in expression starting at /shares/teacher/users/student/mambaforge/envs/jenv/share/julia/packages/MbedTLS/lqmet/src/MbedTLS.jl:1
in expression starting at stdin:3

IJulia [7073ff75-c697-5162-941a-fcdaad2a7d2a]

Failed to precompile IJulia [7073ff75-c697-5162-941a-fcdaad2a7d2a] to "libmbedtls.so".
libmbedx509.so.4: cannot open shared object file: No such file or directory
Stacktrace:
  [1] dlopen(s::String, flags::UInt32; throw_error::Bool)
    @ Base.Libc.Libdl ./libdl.jl:117
  [2] dlopen
    @ ./libdl.jl:116 [inlined]
  [3] dlopen(s::String)
    @ Base.Libc.Libdl ./libdl.jl:116
  [4] __init__()
    @ MbedTLS_jll ~/mambaforge/envs/jenv/share/julia/stdlib/v1.9/MbedTLS_jll/src/MbedTLS_jll.jl:42
  [5] register_restored_modules(sv::Core.SimpleVector, pkg::Base.PkgId, path::String)
    @ Base ./loading.jl:1115
  [6] _include_from_serialized(pkg::Base.PkgId, path::String, ocachepath::String, depmods::Vector{Any})
    @ Base ./loading.jl:1061
  [7] _require_search_from_serialized(pkg::Base.PkgId, sourcepath::String, build_id::UInt128)
    @ Base ./loading.jl:1506
  [8] _require(pkg::Base.PkgId, env::String)
    @ Base ./loading.jl:1783
  [9] _require_prelocked(uuidkey::Base.PkgId, env::String)
    @ Base ./loading.jl:1660
 [10] macro expansion
    @ ./loading.jl:1648 [inlined]
 [11] macro expansion
    @ ./lock.jl:267 [inlined]
 [12] require(into::Module, mod::Symbol)
    @ Base ./loading.jl:1611
 [13] include
    @ ./Base.jl:457 [inlined]
 [14] include_package_for_output(pkg::Base.PkgId, input::String, depot_path::Vector{String}, dl_load_path::Vector{String}, load_path::Vector{String}, concrete_deps::Vector{Pair{Base.PkgId, UInt128}}, source::String)
    @ Base ./loading.jl:2045
 [15] top-level scope
    @ stdin:3
in expression starting at /shares/teacher/users/student/mambaforge/envs/jenv/share/julia/packages/IJulia/Vo51o/src/hmac.jl:1
in expression starting at /shares/teacher/users/student/mambaforge/envs/jenv/share/julia/packages/IJulia/Vo51o/src/IJulia.jl:1
in expression starting at stdin:3

Stacktrace:
 [1] pkgerror(msg::String)
   @ Pkg.Types ~/mambaforge/envs/jenv/share/julia/stdlib/v1.9/Pkg/src/Types.jl:69
 [2] precompile(ctx::Pkg.Types.Context, pkgs::Vector{Pkg.Types.PackageSpec}; internal_call::Bool, strict::Bool, warn_loaded::Bool, already_instantiated::Bool, timing

<details>
<summary>英文:</summary>

I am having trouble installing `IJulia` in Julia 1.9.1 inside a mamba environment. The crux of the issue seems to be the compiler not being able to find MbedTLS even though it is installed

```stdout
Looking for: [&#39;mbedtls&#39;]

conda-forge/noarch                                  13.1MB @   4.4MB/s  3.4s
conda-forge/linux-64                                32.7MB @   4.2MB/s  8.9s

Pinned packages:
  - python 3.11.*


Transaction

  Prefix: /shares/teacher/users/student/mambaforge/envs/jenv

  All requested packages already installed
&gt; Using Pkg
&gt; Pkg.update()
&gt;Pkg.add(&quot;IJulia&quot;) # this works fine
&gt; Using IJulia # This does not

The error when running the above commands is:

MbedTLS [739be429-bea8-5141-9913-cc70e7f3736d]

Failed to precompile MbedTLS [739be429-bea8-5141-9913-cc70e7f3736d] to &quot;/shares/teacher/users/student/mambaforge/envs/jenv/share/julia/compiled/v1.9/MbedTLS/jl_g7s41h&quot;.
ERROR: LoadError: InitError: could not load library &quot;libmbedtls.so&quot;
libmbedx509.so.4: cannot open shared object file: No such file or directory
Stacktrace:
  [1] dlopen(s::String, flags::UInt32; throw_error::Bool)
    @ Base.Libc.Libdl ./libdl.jl:117
  [2] dlopen
    @ ./libdl.jl:116 [inlined]
  [3] dlopen(s::String)
    @ Base.Libc.Libdl ./libdl.jl:116
  [4] __init__()
    @ MbedTLS_jll ~/mambaforge/envs/jenv/share/julia/stdlib/v1.9/MbedTLS_jll/src/MbedTLS_jll.jl:42
  [5] register_restored_modules(sv::Core.SimpleVector, pkg::Base.PkgId, path::String)
    @ Base ./loading.jl:1115
  [6] _include_from_serialized(pkg::Base.PkgId, path::String, ocachepath::String, depmods::Vector{Any})
    @ Base ./loading.jl:1061
  [7] _require_search_from_serialized(pkg::Base.PkgId, sourcepath::String, build_id::UInt128)
    @ Base ./loading.jl:1506
  [8] _require(pkg::Base.PkgId, env::String)
    @ Base ./loading.jl:1783
  [9] _require_prelocked(uuidkey::Base.PkgId, env::String)
    @ Base ./loading.jl:1660
 [10] macro expansion
    @ ./loading.jl:1648 [inlined]
 [11] macro expansion
    @ ./lock.jl:267 [inlined]
 [12] require(into::Module, mod::Symbol)
    @ Base ./loading.jl:1611
 [13] include
    @ ./Base.jl:457 [inlined]
 [14] include_package_for_output(pkg::Base.PkgId, input::String, depot_path::Vector{String}, dl_load_path::Vector{String}, load_path::Vector{String}, concrete_deps::Vector{Pair{Base.PkgId, UInt128}}, source::Nothing)
    @ Base ./loading.jl:2045
 [15] top-level scope
    @ stdin:3
during initialization of module MbedTLS_jll
in expression starting at /shares/teacher/users/student/mambaforge/envs/jenv/share/julia/packages/MbedTLS/lqmet/src/MbedTLS.jl:1
in expression starting at stdin:3

IJulia [7073ff75-c697-5162-941a-fcdaad2a7d2a]

Failed to precompile IJulia [7073ff75-c697-5162-941a-fcdaad2a7d2a] to &quot;/shares/teacher/users/student/mambaforge/envs/jenv/share/julia/compiled/v1.9/IJulia/jl_sxd2YS&quot;.
ERROR: LoadError: InitError: could not load library &quot;libmbedtls.so&quot;
libmbedx509.so.4: cannot open shared object file: No such file or directory
Stacktrace:
  [1] dlopen(s::String, flags::UInt32; throw_error::Bool)
    @ Base.Libc.Libdl ./libdl.jl:117
  [2] dlopen
    @ ./libdl.jl:116 [inlined]
  [3] dlopen(s::String)
    @ Base.Libc.Libdl ./libdl.jl:116
  [4] __init__()
    @ MbedTLS_jll ~/mambaforge/envs/jenv/share/julia/stdlib/v1.9/MbedTLS_jll/src/MbedTLS_jll.jl:42
  [5] register_restored_modules(sv::Core.SimpleVector, pkg::Base.PkgId, path::String)
    @ Base ./loading.jl:1115
  [6] _include_from_serialized(pkg::Base.PkgId, path::String, ocachepath::String, depmods::Vector{Any})
    @ Base ./loading.jl:1061
  [7] _require_search_from_serialized(pkg::Base.PkgId, sourcepath::String, build_id::UInt128)
    @ Base ./loading.jl:1506
  [8] _require(pkg::Base.PkgId, env::String)
    @ Base ./loading.jl:1783
  [9] _require_prelocked(uuidkey::Base.PkgId, env::String)
    @ Base ./loading.jl:1660
 [10] macro expansion
    @ ./loading.jl:1648 [inlined]
 [11] macro expansion
    @ ./lock.jl:267 [inlined]
 [12] require(into::Module, mod::Symbol)
    @ Base ./loading.jl:1611
 [13] include
    @ ./Base.jl:457 [inlined]
 [14] include_package_for_output(pkg::Base.PkgId, input::String, depot_path::Vector{String}, dl_load_path::Vector{String}, load_path::Vector{String}, concrete_deps::Vector{Pair{Base.PkgId, UInt128}}, source::String)
    @ Base ./loading.jl:2045
 [15] top-level scope
    @ stdin:3
during initialization of module MbedTLS_jll
in expression starting at /shares/teacher/users/student/mambaforge/envs/jenv/share/julia/packages/MbedTLS/lqmet/src/MbedTLS.jl:1
in expression starting at stdin:3
ERROR: LoadError: Failed to precompile MbedTLS [739be429-bea8-5141-9913-cc70e7f3736d] to &quot;/shares/teacher/users/student/mambaforge/envs/jenv/share/julia/compiled/v1.9/MbedTLS/jl_TwrfV9&quot;.
Stacktrace:
  [1] error(s::String)
    @ Base ./error.jl:35
  [2] compilecache(pkg::Base.PkgId, path::String, internal_stderr::IO, internal_stdout::IO, keep_loaded_modules::Bool)
    @ Base ./loading.jl:2296
  [3] compilecache
    @ ./loading.jl:2163 [inlined]
  [4] _require(pkg::Base.PkgId, env::String)
    @ Base ./loading.jl:1805
  [5] _require_prelocked(uuidkey::Base.PkgId, env::String)
    @ Base ./loading.jl:1660
  [6] macro expansion
    @ ./loading.jl:1648 [inlined]
  [7] macro expansion
    @ ./lock.jl:267 [inlined]
  [8] require(into::Module, mod::Symbol)
    @ Base ./loading.jl:1611
  [9] include(mod::Module, _path::String)
    @ Base ./Base.jl:457
 [10] include(x::String)
    @ IJulia ~/mambaforge/envs/jenv/share/julia/packages/IJulia/Vo51o/src/IJulia.jl:33
 [11] top-level scope
    @ ~/mambaforge/envs/jenv/share/julia/packages/IJulia/Vo51o/src/IJulia.jl:309
 [12] include
    @ ./Base.jl:457 [inlined]
 [13] include_package_for_output(pkg::Base.PkgId, input::String, depot_path::Vector{String}, dl_load_path::Vector{String}, load_path::Vector{String}, concrete_deps::Vector{Pair{Base.PkgId, UInt128}}, source::Nothing)
    @ Base ./loading.jl:2045
 [14] top-level scope
    @ stdin:3
in expression starting at /shares/teacher/users/student/mambaforge/envs/jenv/share/julia/packages/IJulia/Vo51o/src/hmac.jl:1
in expression starting at /shares/teacher/users/student/mambaforge/envs/jenv/share/julia/packages/IJulia/Vo51o/src/IJulia.jl:1
in expression starting at stdin:3

Stacktrace:
 [1] pkgerror(msg::String)
   @ Pkg.Types ~/mambaforge/envs/jenv/share/julia/stdlib/v1.9/Pkg/src/Types.jl:69
 [2] precompile(ctx::Pkg.Types.Context, pkgs::Vector{Pkg.Types.PackageSpec}; internal_call::Bool, strict::Bool, warn_loaded::Bool, already_instantiated::Bool, timing::Bool, kwargs::Base.Pairs{Symbol, Base.TTY, Tuple{Symbol}, NamedTuple{(:io,), Tuple{Base.TTY}}})
   @ Pkg.API ~/mambaforge/envs/jenv/share/julia/stdlib/v1.9/Pkg/src/API.jl:1581
 [3] precompile(pkgs::Vector{Pkg.Types.PackageSpec}; io::Base.TTY, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ Pkg.API ~/mambaforge/envs/jenv/share/julia/stdlib/v1.9/Pkg/src/API.jl:156
 [4] precompile(pkgs::Vector{Pkg.Types.PackageSpec})
   @ Pkg.API ~/mambaforge/envs/jenv/share/julia/stdlib/v1.9/Pkg/src/API.jl:145
 [5] precompile(; name::Nothing, uuid::Nothing, version::Nothing, url::Nothing, rev::Nothing, path::Nothing, mode::Pkg.Types.PackageMode, subdir::Nothing, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ Pkg.API ~/mambaforge/envs/jenv/share/julia/stdlib/v1.9/Pkg/src/API.jl:171
 [6] precompile()
   @ Pkg.API ~/mambaforge/envs/jenv/share/julia/stdlib/v1.9/Pkg/src/API.jl:162
 [7] top-level scope
   @ REPL[4]:1

I had a read/write error before this and that I was able debug to the png/svg issue!!! There are some older posts that suggested among other things deleting the logo for julia solves read/write issues. As bizarre as that was, I was able to solve it but this MbedTLS issue does not seem to have a whole lot of discussions behind it. If someone is familiar, could you help me get IJulia working?

答案1

得分: 1

我成功找到了一个折中的解决方法,至少允许IJulia进行预编译。首先,我注意到在conda环境的/lib文件夹中,当安装了mbedtls时,正确的.so文件是存在的。然而,看起来Julia并不会在那里查找。我能够通过将环境变量LD_LIBRARY_PATH设置为这个/lib文件夹的绝对路径来解决这个问题。可以通过创建一个小脚本在激活和取消激活环境时自动完成此操作,参见答案。

然而,我仍然面临着编译IJulia的另一个问题,即它找不到文件<conda env>/share/julia/cert.pem。我在<conda env>/ssl文件夹中找到了一个cert.pem文件,并将其复制到了share/julia文件夹中。这似乎起作用了,至少IJulia现在可以无问题地预编译。

英文:

I managed to find a hacky workaround to at least allow IJulia to precompile. First I noticed that in the conda environment /lib folder, the correct .so file exists when mbedtls is installed. However, it looks like Julia doesn't look there. I was able to fix this issue by setting the environment variable LD_LIBRARY_PATH to the absolute path of this /lib folder. This can be done automatically upon activate and deactivate of the environment by making a little script, see this answer.

However, I still faced another issue with compiling IJulia, which was that it couldn't find the file &lt;conda env&gt;/share/julia/cert.pem. I found a cert.pem file in the &lt;conda env&gt;/ssl folder and copied this into the share/julia folder. This seemed to work, at least IJulia now precompiles without issue.

huangapple
  • 本文由 发表于 2023年6月29日 21:51:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/76581689.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定