# What happens if two packages require each other?

**URL:** <https://discourse.julialang.org/t/what-happens-if-two-packages-require-each-other/3108>\
**Category:** General Usage\
**Tags:** question\
**Created:** [April 7, 2017, 7:52pm UTC](https://discourse.julialang.org/t/what-happens-if-two-packages-require-each-other/3108 "2017-04-07T19:52:27Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![djsegal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/djsegal/32/13752_2.png) [@djsegal](https://discourse.julialang.org/u/djsegal)\
**Post date:** [April 7, 2017, 7:52pm UTC](https://discourse.julialang.org/t/what-happens-if-two-packages-require-each-other/3108/1 "2017-04-07T19:52:27Z")

</div>

Has this chicken & the egg problem already been resolved?

* * *

**edit:** for clarity, this could be:

- shallow mutual requiring ( `a` deps on `b` && `b` deps on `a` )
- or requiring each other through some intermediary packages ( `a` deps on `b` deps on `c` deps on `a` )

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [April 7, 2017, 8:02pm UTC](https://discourse.julialang.org/t/what-happens-if-two-packages-require-each-other/3108/2 "2017-04-07T20:02:35Z")

</div>

A “base” package required by both packages should do the trick. It would have the minimal set of code that is needed by the other packages.

---

<div class="post-metadata">

**Author:** ![djsegal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/djsegal/32/13752_2.png) [@djsegal](https://discourse.julialang.org/u/djsegal)\
**Post date:** [April 11, 2017, 5:47am UTC](https://discourse.julialang.org/t/what-happens-if-two-packages-require-each-other/3108/3 "2017-04-11T05:47:36Z")

</div>

Just found [an example](https://juliaobserver.com/packages/AWSLambda)…

So we’re clear, there’s nothing to worry about?

// I’m probably going to hide it on my website otherwise

* * *

see below: `AWSLambda.jl` requires itself (indirectly)

 ![](https://global.discourse-cdn.com/julialang/original/3X/c/0/c049f4b7178166c9447809c469a99260bcd7bc8b.png)

---

<div class="post-metadata">

**Author:** ![tkelman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkelman/32/692_2.png) [@tkelman](https://discourse.julialang.org/u/tkelman)\
**Post date:** [April 11, 2017, 3:04pm UTC](https://discourse.julialang.org/t/what-happens-if-two-packages-require-each-other/3108/4 "2017-04-11T15:04:56Z")

</div>

Circular dependencies may confuse a few scripts people write if they don’t take into account the possibility they might happen, but Pkg doesn’t have any problems with them. It might hit some corner cases in precompilation, hard to tell unless anyone finds an issue.

---

<div class="post-metadata">

**Author:** ![djsegal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/djsegal/32/13752_2.png) [@djsegal](https://discourse.julialang.org/u/djsegal)\
**Post date:** [April 11, 2017, 6:23pm UTC](https://discourse.julialang.org/t/what-happens-if-two-packages-require-each-other/3108/5 "2017-04-11T18:23:00Z")

</div>

Sounds good. Thanks for looking into it!

* * *

Some more info before closing this:

Currently `AWSLambda` and `AWSSNS` are the only packages with circular dependencies.

Regardless,

- I now hide circular dependencies on the site
- but print them all to the logs every data update

---

<div class="post-metadata">

**Author:** ![QuantumBits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/quantumbits/32/2917_2.png) [@QuantumBits](https://discourse.julialang.org/u/QuantumBits)\
**Post date:** [January 6, 2021, 3:30am UTC](https://discourse.julialang.org/t/what-happens-if-two-packages-require-each-other/3108/6 "2021-01-06T03:30:27Z")

</div>

Is it still true that packages are allowed to depend on one another in Julia/Pkg v1.5.3+?

I’m maintaining some private registries for my work, and we need these packages to behave as “nodes” in a closed-loop feedback system. For example, the output of Package A feeds into Package B feeds into Package C feeds back into Package A. Or, alternatively, Package A depends on B depends on C depends on A.

Perhaps there’s a better way to reorganize things, but for the time being Julia/Pkg returns “AssertionError: sourcepath !== nothing” when I run “pkg\> instantiate” on Package A, B or C in this example. I’ve been noticing people saying that Julia/Pkg doesn’t (or shouldn’t) support circular dependencies, but at least in my case I feel like it’s more a feature than a bug.

Any updates on this would be great, thank you!

---

<div class="post-metadata">

**Author:** ![tisztamo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tisztamo/32/16200_2.png) [@tisztamo](https://discourse.julialang.org/u/tisztamo)\
**Post date:** [January 6, 2021, 9:48am UTC](https://discourse.julialang.org/t/what-happens-if-two-packages-require-each-other/3108/7 "2021-01-06T09:48:08Z")

</div>

> [@QuantumBits](#):
>
> Perhaps there’s a better way to reorganize things

I would feel uncomfortable with a circular dependency setup for that, even if it would work. E.g. separating out the loop into a project that depends on all the others seems possible.

Alternatively, or if the loop is the materialization of some general “lifecycle”, then I would create the lifecycle package as the “root” without any dependencies. A, B and C would depend only on the lifecycle package (getting input from it and providing output, by implementing an interface), and the system would be assembled in a project that depends on all of them.

---

<div class="post-metadata">

**Author:** ![QuantumBits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/quantumbits/32/2917_2.png) [@QuantumBits](https://discourse.julialang.org/u/QuantumBits)\
**Post date:** [January 7, 2021, 7:44pm UTC](https://discourse.julialang.org/t/what-happens-if-two-packages-require-each-other/3108/8 "2021-01-07T19:44:52Z")

</div>

Yeah, this is something I’ve been afraid I’d need to accept sooner or later, but I think you’re 100% correct that it’s just better to reorganize things. There’s a difference between project dependencies (i.e. what Julia/Pkg manages) and data input/output dependencies, which until now I’ve been basically conflating.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [January 7, 2021, 8:31pm UTC](https://discourse.julialang.org/t/what-happens-if-two-packages-require-each-other/3108/9 "2021-01-07T20:31:30Z")

</div>

I haven’t tried, but I believe it’s still allowed. As you’ve already concluded though, it’s best to avoid.

---

<div class="post-metadata">

**Author:** ![QuantumBits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/quantumbits/32/2917_2.png) [@QuantumBits](https://discourse.julialang.org/u/QuantumBits)\
**Post date:** [January 7, 2021, 9:27pm UTC](https://discourse.julialang.org/t/what-happens-if-two-packages-require-each-other/3108/10 "2021-01-07T21:27:30Z")

</div>

So, it’s kind of inconsistent to me at least - I get that `sourcepath !== nothing` assertion error when I run `pkg> instantiate`, but if I try `pkg> update` my project dependencies seem to shake out alright (including getting downloaded).

For reference, I’m seeing this kind of error: [https://github.com/JuliaLang/Pkg.jl/issues/2097](https://github.com/JuliaLang/Pkg.jl/issues/2097)

And the “offending” line producing that `AssertionError` is here: [https://github.com/JuliaLang/Pkg.jl/blob/becccb374edaccb662b106c305a77b1db4a64079/src/Operations.jl#L1665](https://github.com/JuliaLang/Pkg.jl/blob/becccb374edaccb662b106c305a77b1db4a64079/src/Operations.jl#L1665)

For context, here is my Julia setup:

```julia
julia> versioninfo()
Julia Version 1.5.3
Commit 788b2c77c1 (2020-11-09 13:37 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-9.0.1 (ORCJIT, skylake)

```
