# Are extension packages importable?

**URL:** <https://discourse.julialang.org/t/are-extension-packages-importable/92527>\
**Category:** General Usage\
**Tags:** package-extensions\
**Created:** [January 4, 2023, 9:15pm UTC](https://discourse.julialang.org/t/are-extension-packages-importable/92527 "2023-01-04T21:15:14Z")\
**Posts on this page:** 7\
**Page:** 2

<div class="post-metadata">

**Author:** ![hhaensel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hhaensel/32/1207_2.png) [@hhaensel](https://discourse.julialang.org/u/hhaensel)\
**Post date:** [April 27, 2023, 6:20am UTC](https://discourse.julialang.org/t/are-extension-packages-importable/92527/22 "2023-04-27T06:20:51Z")

</div>

Thanks for your reply. I was experiencing exactly that when I tried to use it in a package.

But wouldn’t it be possible to create a new import statement that would do what the macro does at compile time?

---

<div class="post-metadata">

**Author:** ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Post date:** [July 21, 2023, 8:50am UTC](https://discourse.julialang.org/t/are-extension-packages-importable/92527/23 "2023-07-21T08:50:31Z")

</div>

Sorry for necroposting but a [similar question](https://discourse.julialang.org/t/package-extensions-structs-inside-extensions/101849) has just popped up for the 100th time, and the answer relied on a long lost Slack thread. I think it’s time to put this knowledge in the docs.  
Anyone want to help with this PR or review it?

> <https://github.com/JuliaLang/Pkg.jl/pull/3552>
>
> Partial fix for #3499 
> 
> It's a very minimal addition and I would welcome more …contributions

---

<div class="post-metadata">

**Author:** ![MilesCranmer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/milescranmer/32/21070_2.png) [@MilesCranmer](https://discourse.julialang.org/u/MilesCranmer)\
**Post date:** [August 6, 2023, 2:56am UTC](https://discourse.julialang.org/t/are-extension-packages-importable/92527/24 "2023-08-06T02:56:35Z")

</div>

Cross-posting a related issue: [KeyError on internal use of extensions · Issue #50028 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/50028)

The basic idea is that you could have a package in `[deps]` (so it would automatically be installed; without the user needing to do it themselves), but _load it as an extension_, such as by calling a function:

```julia
function call_zygote_function(arg)
    Base.require(@ __MODULE__ , :Zygote)
    Base.invokelatest(my_zygote_function, arg)
end

```

which should trigger a Zygote.jl-containing extension to load. However, this does not yet work due to how the extension mechanism requires the package to be in `[weakdeps]`. It sounds like there’s nothing fundamental preventing this from working though, so it could be a nice way to conditionally load code from within a package while taking advantage of precompilation.

---

<div class="post-metadata">

**Author:** ![Allan\_Baker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/allan_baker/32/42645_2.png) [@Allan\_Baker](https://discourse.julialang.org/u/Allan_Baker)\
**Post date:** [August 15, 2023, 2:50pm UTC](https://discourse.julialang.org/t/are-extension-packages-importable/92527/25 "2023-08-15T14:50:28Z")

</div>

I’ve been google circling around an answer to my question and it comes near this one. It seems to me there is a valid use case for new methods in an extension.

I want to have my module have only the relevant plotting routines for Plots.jl and Makie.jl and I don’t want them loaded with the package unless the user decides to do some plotting.

I’m having a lot of difficulty getting this to work cleanly. The Makie recipes need me to predefine an empty copy of the ultimate method for plotting the object in the parent module and then import it.

I haven’t quite figured it out for the RecipesBase plot overload.

Any thoughts on the best practice for this?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [August 15, 2023, 8:17pm UTC](https://discourse.julialang.org/t/are-extension-packages-importable/92527/26 "2023-08-15T20:17:39Z")

</div>

Maybe this helps as one example [GitHub - jkrumbiegel/MakiePkgExtTest](https://github.com/jkrumbiegel/MakiePkgExtTest)

---

<div class="post-metadata">

**Author:** ![oliviermilla](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oliviermilla/32/47200_2.png) [@oliviermilla](https://discourse.julialang.org/u/oliviermilla)\
**Post date:** [September 28, 2023, 7:22pm UTC](https://discourse.julialang.org/t/are-extension-packages-importable/92527/27 "2023-09-28T19:22:02Z")

</div>

I agree here and I’ve circled too. Have you found the way to the force?

---

<div class="post-metadata">

**Author:** ![Allan\_Baker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/allan_baker/32/42645_2.png) [@Allan\_Baker](https://discourse.julialang.org/u/Allan_Baker)\
**Post date:** [October 2, 2023, 5:42pm UTC](https://discourse.julialang.org/t/are-extension-packages-importable/92527/28 "2023-10-02T17:42:35Z")

</div>

Not with the Recipes. I got the extensions to work in general though. I just didn’t use the recipes to do it. I just made up a function and called that.

[Previous page](https://discourse.julialang.org/t/are-extension-packages-importable/92527.md?page=1)
