# Loading a package that is not part of the dependnecies

**URL:** <https://discourse.julialang.org/t/loading-a-package-that-is-not-part-of-the-dependnecies/91011>\
**Category:** General Usage\
**Tags:** question, package, dependencies\
**Created:** [November 29, 2022, 8:49pm UTC](https://discourse.julialang.org/t/loading-a-package-that-is-not-part-of-the-dependnecies/91011 "2022-11-29T20:49:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bugzaren](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bugzaren/32/18749_2.png) [@Bugzaren](https://discourse.julialang.org/u/Bugzaren)\
**Post date:** [November 29, 2022, 8:49pm UTC](https://discourse.julialang.org/t/loading-a-package-that-is-not-part-of-the-dependnecies/91011/1 "2022-11-29T20:49:15Z")

</div>

Hi,

I have a feeling I’m going about his the wrong way, so I’m happy to be told how to do it properly.

I have package `MajoranaReps` wants to load `MathLink` if it is installed. However, since `MathLink` uses proprietary software (Mathematica) i cannot rely/nor force everyone to install it.  
Also `MajoranaReps` works fine even without `MathLink`, it just loses some functionality.

To solve its i added a check when the package loads to check if `MathLink` is installed

```julia
isinstalled(pkg::String) = any(x -> x.name == pkg && x.is_direct_dep, values(Pkg.dependencies()))
HasMathLink=isinstalled("MathLink")

if HasMathLink
    using MathLink ###if Mathlink is present also load it...
end

```

This solution passes the JuliRegistrator auto-merge checks so i was happy.

However when trying to load the package with `using MajoranaReps` I get the error

```julia
ERROR: LoadError: ArgumentError: Package MajoranaReps does not have MathLink in its dependencies:

```

To summarize: I do not want to add `MathLink` as a dependency in the .toml file (since uses would need to install mathematica), but I still want to be able to load `MathLink` if is exists.

How to i do this the proper way?

---

<div class="post-metadata">

**Author:** ![SteffenPL](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steffenpl/32/206270_2.png) [@SteffenPL](https://discourse.julialang.org/u/SteffenPL)\
**Post date:** [November 30, 2022, 12:40pm UTC](https://discourse.julialang.org/t/loading-a-package-that-is-not-part-of-the-dependnecies/91011/2 "2022-11-30T12:40:54Z")

</div>

How about a second package which contains all the optional, Mathlink-dependent code?

---

<div class="post-metadata">

**Author:** ![kellertuer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kellertuer/32/220707_2.png) [@kellertuer](https://discourse.julialang.org/u/kellertuer)\
**Post date:** [November 30, 2022, 1:20pm UTC](https://discourse.julialang.org/t/loading-a-package-that-is-not-part-of-the-dependnecies/91011/3 "2022-11-30T13:20:04Z")

</div>

I am not 100% sure I understand your use case: You are developing MajoranaReps.jl?

Then you could do something with `requires.jl` like we did here

> <https://github.com/JuliaManifolds/Manifolds.jl/blob/2da9dd9a4fc157f66e5ef617c927f3e38bf2d244/src/Manifolds.jl#L472-L476>

This does the following: If you either have loaded Plots (that is `using Plots) _before_ or _after_ `using Manifolds, the part of `recipes.jl` (that is plotting stuff we define) is loaded.

For that to work add `MathLink` to the extras, see

> <https://github.com/JuliaManifolds/Manifolds.jl/blob/2da9dd9a4fc157f66e5ef617c927f3e38bf2d244/Project.toml#L60>

_edit:_ note that the `using`s we have in the first code snippet just load those packages _within_ our package, if you want to bring more stuff to the users namespace you will have to add exports in that part as well.
