# "Error Importing Custom Julia Package: UndefVarError: Zygote not defined Despite Dependency Declaration"

**URL:** <https://discourse.julialang.org/t/error-importing-custom-julia-package-undefvarerror-zygote-not-defined-despite-dependency-declaration/122587>\
**Category:** General Usage\
**Tags:** question, package, import\
**Created:** [November 13, 2024, 2:23pm UTC](https://discourse.julialang.org/t/error-importing-custom-julia-package-undefvarerror-zygote-not-defined-despite-dependency-declaration/122587 "2024-11-13T14:23:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![josemanuel22](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/josemanuel22/32/20668_2.png) [@josemanuel22](https://discourse.julialang.org/u/josemanuel22)\
**Post date:** [November 13, 2024, 2:23pm UTC](https://discourse.julialang.org/t/error-importing-custom-julia-package-undefvarerror-zygote-not-defined-despite-dependency-declaration/122587/1 "2024-11-13T14:23:59Z")

</div>

I’m trying to import a developed package, but I get the following error:

```julia
julia> using RandomProjections
[Info: Precompiling RandomProjections [acf8f2c6-418f-403f-a7f7-d35fd4a663f5]
ERROR: LoadError: UndefVarError: `Zygote` not defined
Stacktrace:
 [1] top-level scope
   @ :0
 [2] include
   @ ./Base.jl:457 [inlined]
 [3] include_package_for_output(pkg::Base.PkgId, input::String, depot_path::Vector{String}, dl_load_path::Vector{String}, load_path::Vector{String}, concrete_deps::Vector{Pair{Base.PkgId, UInt128}}, source::String)
   @ Base ./loading.jl:2010
 [4] top-level scope
   @ stdin:2
in expression starting at /Users/jmfrutos/.julia/dev/RandomProjections/src/RandomProjections.jl:117
in expression starting at /Users/jmfrutos/.julia/dev/RandomProjections/src/RandomProjections.jl:117
in expression starting at stdin:2
ERROR: Failed to precompile RandomProjections [acf8f2c6-418f-403f-a7f7-d35fd4a663f5] to "/Users/jmfrutos/.julia/compiled/v1.9/RandomProjections/jl_55w7Tu".

```

I’m not quite sure why, since Zygote is listed in my dependencies:

```julia
name = "RandomProjections"
uuid = "acf8f2c6-418f-403f-a7f7-d35fd4a663f5"
authors = ["José Manuel de Frutos"]
version = "1.0.0-DEV"

[deps]
Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c"
KernelDensity = "5ab0869b-81aa-558d-bb23-cbf5423bbe9b"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Memoize = "c03570c3-d221-55d1-a50c-7939bbd78826"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"

```

---

<div class="post-metadata">

**Author:** ![BioTurboNick](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bioturbonick/32/6380_2.png) [@BioTurboNick](https://discourse.julialang.org/u/BioTurboNick)\
**Post date:** [November 13, 2024, 2:46pm UTC](https://discourse.julialang.org/t/error-importing-custom-julia-package-undefvarerror-zygote-not-defined-despite-dependency-declaration/122587/2 "2024-11-13T14:46:13Z")

</div>

Not defined likely means you’re missing `using Zygote` somewhere in the code itself?

---

<div class="post-metadata">

**Author:** ![josemanuel22](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/josemanuel22/32/20668_2.png) [@josemanuel22](https://discourse.julialang.org/u/josemanuel22)\
**Post date:** [November 13, 2024, 2:46pm UTC](https://discourse.julialang.org/t/error-importing-custom-julia-package-undefvarerror-zygote-not-defined-despite-dependency-declaration/122587/3 "2024-11-13T14:46:46Z")

</div>

I have it

```julia
module RandomProjections

export RandomProjection, apply_defining_function, get_powers, homopoly, linear_projection, poly_projection, circular_projection, random_slice, get_slice, max_rand_proj, max_rand_proj_with_nn

using Flux
using Zygote
using Random
using LinearAlgebra
using ProgressMeter
using Memoize

```

---

<div class="post-metadata">

**Author:** ![BioTurboNick](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bioturbonick/32/6380_2.png) [@BioTurboNick](https://discourse.julialang.org/u/BioTurboNick)\
**Post date:** [November 13, 2024, 2:50pm UTC](https://discourse.julialang.org/t/error-importing-custom-julia-package-undefvarerror-zygote-not-defined-despite-dependency-declaration/122587/4 "2024-11-13T14:50:04Z")

</div>

Hmm. What at line 117, where it is pointing?

---

<div class="post-metadata">

**Author:** ![josemanuel22](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/josemanuel22/32/20668_2.png) [@josemanuel22](https://discourse.julialang.org/u/josemanuel22)\
**Post date:** [November 13, 2024, 2:51pm UTC](https://discourse.julialang.org/t/error-importing-custom-julia-package-undefvarerror-zygote-not-defined-despite-dependency-declaration/122587/5 "2024-11-13T14:51:55Z")

</div>

Yes, sorry, first line is 117

```julia
Zygote.@nograd function get_powers(dim::Int, degree::Int)
    """
    Generates the powers of a homogeneous polynomial.

    Example:
    get_powers(2, 3) -> [(0, 3), (1, 2), (2, 1), (3, 0)]
    get_powers(3, 2) -> [(0, 0, 2), (0, 1, 1), (0, 2, 0), (1, 0, 1), (1, 1, 0), (2, 0, 0)]
    """
    if dim == 1
        return [(degree,)]
    else
        result = []
        for value in 0:degree
            for permutation in get_powers(dim - 1, degree - value)
                push!(result, tuple(value, permutation...)) # Concatenating the current value with the permutation
            end
        end
        return result
    end
end

```

---

<div class="post-metadata">

**Author:** ![BioTurboNick](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bioturbonick/32/6380_2.png) [@BioTurboNick](https://discourse.julialang.org/u/BioTurboNick)\
**Post date:** [November 13, 2024, 3:01pm UTC](https://discourse.julialang.org/t/error-importing-custom-julia-package-undefvarerror-zygote-not-defined-despite-dependency-declaration/122587/6 "2024-11-13T15:01:55Z")

</div>

I wonder if having the exports before the usings is doing something?

Other than that, I assume you’ve tried reloading the REPL?
