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

Specify backend while "using Plots" with PlutoPkg #1305

Open
DebChanda opened this issue Jul 11, 2021 · 5 comments
Open

Specify backend while "using Plots" with PlutoPkg #1305

DebChanda opened this issue Jul 11, 2021 · 5 comments

Comments

@DebChanda
Copy link

I am using the built-in package manager of Pluto. Is there a working example where I can see how to use different backends with Plots, currently gr and plotly are working by default. pyplot gives

ArgumentError: Package PyPlot not found in current path:
- Run `import Pkg; Pkg.add("PyPlot")` to install the PyPlot package.

    top-level scope@backends.jl:507
    eval@boot.jl:360[inlined]
    _initialize_backend(::Plots.PyPlotBackend)@backends.jl:506
    backend@backends.jl:174[inlined]
    var"#pyplot#259"(::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, ::typeof(Plots.pyplot))@backends.jl:31
    pyplot@backends.jl:31[inlined]
    top-level scope@Local: 1[inlined]
@lllusion3418
Copy link

One workaround to get Pluto to add PyPlot.jl to the environment is to simply import it like this (instead of using PyPlot as not to pollute the scope):
Screenshot_20210711_190749

But the user experience with this error message is not ideal - there's no need to give up on PlutoPkg (which is what the suggested snippet would do) just to be able to use the PyPlot backend.

@fonsp
Copy link
Owner

fonsp commented Jul 12, 2021

Like @lllusion3418 suggested, import the backend package before importing Plots, eg:

begin
    import PyPlot
    using Plots
end

By importing it, you tell Pluto that the package should be installed in the env, making it available to Plots.jl.

@fonsp
Copy link
Owner

fonsp commented Jul 12, 2021

The choice to shield your notebook from knowing about a global installation of PyPlot is deliberate: we want notebooks to run independently of what packages you have installed elsewhere.

If not isolated, you might have a hidden dependency on the global PyPlot installation. Someone else opening your notebook would not be able to run it.

@fonsp
Copy link
Owner

fonsp commented Jul 12, 2021

@lllusion3418 (and others) feel free to add a PR to "detect and rewrite" that error message. Take a look at https://github.com/fonsp/Pluto.jl/blob/main/frontend/components/ErrorMessage.js

@DebChanda
Copy link
Author

DebChanda commented Jul 13, 2021

Suggestion of @lllusion3418 works for me, you can close this issue. Or, if you want to keep it open to discuss about the error message, thats also fine. Also, you can add this suggestion in the documentation of PlutoPkg, so others can easily find it.

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

No branches or pull requests

3 participants