# How to find missing dependencies of .jl file without executing it

**URL:** <https://discourse.julialang.org/t/how-to-find-missing-dependencies-of-jl-file-without-executing-it/47049>\
**Category:** General Usage\
**Created:** [September 22, 2020, 6:35am UTC](https://discourse.julialang.org/t/how-to-find-missing-dependencies-of-jl-file-without-executing-it/47049 "2020-09-22T06:35:59Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![pauljurczak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pauljurczak/32/921_2.png) [@pauljurczak](https://discourse.julialang.org/u/pauljurczak)\
**Post date:** [September 22, 2020, 6:35am UTC](https://discourse.julialang.org/t/how-to-find-missing-dependencies-of-jl-file-without-executing-it/47049/1 "2020-09-22T06:35:59Z")

</div>

I have a program consisting of a single .jl file, which is using a bunch of packages with directive `using`. There is more of them than absolutely necessary, since sometimes it’s not clear from documentation what is the base minimum. I would like to minimize their number, but it is painful to do so by trial and error. Running my program requires a complicated system setup, which takes time and is hard to undo when REPL reports an error due to a missing dependency.

Is there a way to parse/analyze the program to check for missing dependecies?

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [September 22, 2020, 7:05am UTC](https://discourse.julialang.org/t/how-to-find-missing-dependencies-of-jl-file-without-executing-it/47049/2 "2020-09-22T07:05:49Z")

</div>

You can use some heuristics and guessing based on the name used but no it’s in general impossible to do. It’s not even something you can figure out simply by running the program either.

---

<div class="post-metadata">

**Author:** ![lobingera](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lobingera/32/211_2.png) [@lobingera](https://discourse.julialang.org/u/lobingera)\
**Post date:** [September 22, 2020, 7:43am UTC](https://discourse.julialang.org/t/how-to-find-missing-dependencies-of-jl-file-without-executing-it/47049/3 "2020-09-22T07:43:39Z")

</div>

Can this be turned around? So that after running this single .jl all used/visited dependencies are listed?

---

<div class="post-metadata">

**Author:** ![heliosdrm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heliosdrm/32/3851_2.png) [@heliosdrm](https://discourse.julialang.org/u/heliosdrm)\
**Post date:** [September 22, 2020, 9:15am UTC](https://discourse.julialang.org/t/how-to-find-missing-dependencies-of-jl-file-without-executing-it/47049/4 "2020-09-22T09:15:49Z")

</div>

One way to confirm that a package `Foo` is needed:

1. Search if the name `Foo` is used in the code – let aside the line with `using Foo`.
2. Search if any of the names exported by `Foo` – get them with `names(Foo)` – are used.

If any of those conditions is met, you do need `Foo`.

You may still need it, even if no exported name is used, if `Foo` extends methods of other modules, but it’s a start.

---

<div class="post-metadata">

**Author:** ![tomerarnon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomerarnon/32/3170_2.png) [@tomerarnon](https://discourse.julialang.org/u/tomerarnon)\
**Post date:** [September 22, 2020, 10:36am UTC](https://discourse.julialang.org/t/how-to-find-missing-dependencies-of-jl-file-without-executing-it/47049/5 "2020-09-22T10:36:47Z")

</div>

If you expect subsequent runs of the program to be identical in their library usage – i.e. the types and methods encountered during one run should be identical to those in all future runs – you can certainly extract all of the compiled methods, including what module they come from, using e.g. the julia profiler, or perhaps a tool like MethodAnalysis.jl.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [September 22, 2020, 10:49am UTC](https://discourse.julialang.org/t/how-to-find-missing-dependencies-of-jl-file-without-executing-it/47049/6 "2020-09-22T10:49:40Z")

</div>

> [@pauljurczak](#):
>
> since sometimes it’s not clear from documentation what is the base minimum

Generally you would only be `using` those packages from which you need some symbols (functions, or variables). A common additional case is conditional loading via Requires.jl.

> [@pauljurczak](#):
>
> Running my program requires a complicated system setup, which takes time and is hard to undo when REPL reports an error due to a missing dependency.

Set up a test script you can call from the command line that performs a very simplified version of your calculation.

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [September 22, 2020, 1:17pm UTC](https://discourse.julialang.org/t/how-to-find-missing-dependencies-of-jl-file-without-executing-it/47049/7 "2020-09-22T13:17:31Z")

</div>

> [@lobingera](#):
>
> Can this be turned around? So that after running this single .jl all used/visited dependencies are listed?

Well, that’s the part that I said is also generally impossible.

You can certainly come up with some rules to keep tack of what you use, but those are still just heuristics. There can be packages that’s needed for some methods but not any new symbols that you use directly. Or ones that registers global handlers for a different package. Ones that provides data for other package. Also what do you do for names used only in untake branches (these are easy to scan from the source but much harder when collecting data from a run). How do you distinguish features that are truely not needed vs ones that just happens to be unneeded in a run.

---

<div class="post-metadata">

**Author:** ![pauljurczak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pauljurczak/32/921_2.png) [@pauljurczak](https://discourse.julialang.org/u/pauljurczak)\
**Post date:** [September 22, 2020, 2:49pm UTC](https://discourse.julialang.org/t/how-to-find-missing-dependencies-of-jl-file-without-executing-it/47049/8 "2020-09-22T14:49:45Z")

</div>

> [@tomerarnon](#):
>
> If you expect subsequent runs of the program to be identical in their library usage

Unfortunately, this is not a case. The project involves constant experimenting in very fluid environment. It may stabilize some day, so this could become a viable option.

---

<div class="post-metadata">

**Author:** ![pauljurczak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pauljurczak/32/921_2.png) [@pauljurczak](https://discourse.julialang.org/u/pauljurczak)\
**Post date:** [September 22, 2020, 2:54pm UTC](https://discourse.julialang.org/t/how-to-find-missing-dependencies-of-jl-file-without-executing-it/47049/9 "2020-09-22T14:54:15Z")

</div>

> [@heliosdrm](#):
>
> One way to confirm that a package `Foo` is needed

It would be nice to have a tool to do it automagically. It doesn’t have to be perfect or even near the theoretical limit of static dependency verification.
