Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERROR: Cannot set preferences of an unknown package that is not loaded! #551

Open
schlichtanders opened this issue Oct 17, 2024 · 4 comments

Comments

@schlichtanders
Copy link

Trying to define the preferences for RCall, I am running into an error. How to actually do this?

julia> import Pkg; Pkg.add(["UUIDs", "Preferences", "CondaPkg"])

julia> using UUIDs, Preferences, CondaPkg

julia> envdir = CondaPkg.envdir()

julia> RCALL_UUID = UUID("6f49c342-dc21-5d91-9882-a32aef131414")
UUID("6f49c342-dc21-5d91-9882-a32aef131414")

julia> set_preferences!(RCALL_UUID, "Rhome" => "$envdir/lib/R", "libR" => "$envdir/lib/R/lib/libR.so")
ERROR: Cannot set preferences of an unknown package that is not loaded!
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:35
 [2] set_preferences!(::UUID, ::Pair{String, String}, ::Vararg{Pair{String, String}}; export_prefs::Bool, active_project_only::Bool, kwargs::@Kwargs{})
   @ Preferences ~/.julia/packages/Preferences/enLcN/src/Preferences.jl:281
 [3] set_preferences!(::UUID, ::Pair{String, String}, ::Pair{String, String})
   @ Preferences ~/.julia/packages/Preferences/enLcN/src/Preferences.jl:223
 [4] top-level scope
   @ REPL[8]:1
@schlichtanders
Copy link
Author

It seems the only way to actually fix this is to first add the RCall package (which will trigger precompilation of RCall) and then add the preferences like above.

I tried writing the LocalPreferences.toml directly, but it won't actually work, has_preferences will simply show false as long as RCall is not a top-level dependency, even if the preferences are set inside LocalPreferences.toml

@palday
Copy link
Collaborator

palday commented Oct 17, 2024

I think this setup is also desirable behavior -- I think it makes sense to require direct dependency for something you care enough about the details of to set a preference on.

@schlichtanders
Copy link
Author

The confusing part is on reading the preferences. Despite having LocalPreferences.toml filled with an entry for RCall, you will get the following divergent behaviour between UUID and package-name, if RCall is not added as a toplevel dependency.

julia> using Preferences, UUIDs

julia> RCALL_UUID = UUID("6f49c342-dc21-5d91-9882-a32aef131414")

julia> has_preference(RCALL_UUID, "Rhome")
false

julia> has_preference("RCall", "Rhome")
ERROR: ArgumentError: Cannot resolve package 'RCall' in load path; have you added the package as a top-level dependency?
Stacktrace:
 [1] package_lookup_error(name::String)
   @ Preferences ~/.julia/packages/Preferences/enLcN/src/utils.jl:88
 [2] has_preference(name::String, key::String)
   @ Preferences ~/.julia/packages/Preferences/enLcN/src/Preferences.jl:76
 [3] top-level scope
   @ REPL[8]:1

@frankier
Copy link
Contributor

This might be relevant/helpful: JuliaPackaging/Preferences.jl#53

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants