# Precompilation error. 'LoadError: UndefVarError: \`@printf\` not defined'

**URL:** <https://discourse.julialang.org/t/precompilation-error-loaderror-undefvarerror-printf-not-defined/107043>\
**Category:** General Usage\
**Tags:** question, precompilation, toml\
**Created:** [December 2, 2023, 12:23pm UTC](https://discourse.julialang.org/t/precompilation-error-loaderror-undefvarerror-printf-not-defined/107043 "2023-12-02T12:23:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Purvaash](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/purvaash/32/22648_2.png) [@Purvaash](https://discourse.julialang.org/u/Purvaash)\
**Post date:** [December 2, 2023, 12:23pm UTC](https://discourse.julialang.org/t/precompilation-error-loaderror-undefvarerror-printf-not-defined/107043/1 "2023-12-02T12:23:57Z")

</div>

Hi, I am new to Julia and Julia Discourse. I am facing the following error.

I am trying to set up an environment that I found in a Git repository. The steps I followed are:

1. git clone [23tn / 23tn-julia · GitLab](https://gitlab.physik.uni-muenchen.de/23tn/23tn-julia.git)
2. Opened Julia in the terminal (from the cloned folder) and, `] add .`
3. `activate .`. Now `(@v1.9) pkg>` changed to `(tn_julia) pkg>`.
4. Continuing in package mode, `instantiate`
5. At the end of the process, I encountered the following error,

```julia
        Info Packages marked with ⌅ have new versions available but compatibility constraints restrict them from upgrading. To see why use `status --outdated -m`
Precompiling project...
  ✗ tn_julia
  0 dependencies successfully precompiled in 11 seconds. 151 already precompiled.
  1 dependency errored. To see a full report either run `import Pkg; Pkg.precompile()` or load the package

```

1. I tried precompile,  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/8/3/8339c7b792a30614cf51ecb4e98417011a880efc.png)
2. The error I get is, ERROR: LoadError: UndefVarError: `@printf` not defined

```julia
Stacktrace:
 [1] top-level scope
   @ :0
 [2] include(mod::Module, _path::String)
   @ Base .\Base.jl:457
 [3] include(x::String)
   @ tn_julia E:\tn\23tn-julia\src\tn_julia.jl:1
 [4] top-level scope
   @ E:\tn\23tn-julia\src\tn_julia.jl:10
 [5] include
   @ .\Base.jl:457 [inlined]
 [6] 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::Nothing)       
   @ Base .\loading.jl:2049
 [7] top-level scope
   @ stdin:3
in expression starting at E:\tn\23tn-julia\src\DMRG.jl:508
in expression starting at E:\tn\23tn-julia\src\DMRG.jl:339
in expression starting at E:\tn\23tn-julia\src\tn_julia.jl:1
in expression starting at stdin:3

julia> Pkg.test("Printf")
ERROR: UndefVarError: `Pkg` not defined
Stacktrace:
 [1] top-level scope
   @ REPL[5]:1

julia> using Pkg

julia> Pkg.test("Printf")
     Testing Printf
      Status `C:\Users\purva\AppData\Local\Temp\jl_BdrBIv\Project.toml`
  [de0858da] Printf
  [8dfed614] Test
  [4ec0a83e] Unicode
      Status `C:\Users\purva\AppData\Local\Temp\jl_BdrBIv\Manifest.toml`
  [2a0f44e3] Base64
  [b77e0a4c] InteractiveUtils
  [56ddb016] Logging
  [d6f4376e] Markdown
  [de0858da] Printf
  [9a3f8284] Random
  [ea8e919c] SHA v0.7.0
  [9e88b42a] Serialization
  [8dfed614] Test
  [4ec0a83e] Unicode
     Testing Running tests...
Test Summary: | Pass Total Time
Printf | 1017 1017 22.4s
     Testing Printf tests passed 

(tn_julia) pkg> precompile
Precompiling project...
  ✗ tn_julia
  0 dependencies successfully precompiled in 9 seconds. 151 already precompiled.

ERROR: The following 1 direct dependency failed to precompile:

tn_julia [53662e65-01d4-4314-8931-2bffaf2f7422]

Failed to precompile tn_julia [53662e65-01d4-4314-8931-2bffaf2f7422] to "C:\\Users\\purva\\.julia\\compiled\\v1.9\\tn_julia\\jl_69FE.tmp".
ERROR: LoadError: UndefVarError: `@printf` not defined
Stacktrace:
 [1] top-level scope
   @ :0
 [2] include(mod::Module, _path::String)
   @ Base .\Base.jl:457
 [3] include(x::String)
   @ tn_julia E:\tn\23tn-julia\src\tn_julia.jl:1
 [4] top-level scope
   @ E:\tn\23tn-julia\src\tn_julia.jl:10
 [5] include
   @ .\Base.jl:457 [inlined]
 [6] 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::Nothing)       
   @ Base .\loading.jl:2049
 [7] top-level scope
   @ stdin:3
in expression starting at E:\tn\23tn-julia\src\DMRG.jl:508
in expression starting at E:\tn\23tn-julia\src\DMRG.jl:339
in expression starting at E:\tn\23tn-julia\src\tn_julia.jl:1
in expression starting at stdin:3

```

The code in tn\_julia.jl is,

```julia
module tn_julia

export getLocalSpace, getIdentity, contract, updateLeft

include("getLocalSpace.jl")
include("getIdentity.jl")
include("contract.jl")
include("updateleft.jl")
include("MPS.jl")
include("DMRG.jl")

end # module

```

Thanks in advance for any help/suggestions.

PS: I am familiar with basic level Julia. When providing help/suggestions, I would appreciate it if you keep this in mind.

---

<div class="post-metadata">

**Author:** ![Fliks](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fliks/32/2494_2.png) [@Fliks](https://discourse.julialang.org/u/Fliks)\
**Post date:** [December 11, 2023, 10:37am UTC](https://discourse.julialang.org/t/precompilation-error-loaderror-undefvarerror-printf-not-defined/107043/2 "2023-12-11T10:37:17Z")

</div>

Hi,

the problem seems to be that the code you want to load uses the `@printf` macro in the code but does not load the Printf standard library.  
You would have to fix the code your self by including `using Printf: @printf` in the module definition of tn\_julia or convince the maintainer of the tutorial to do it.

---

<div class="post-metadata">

**Author:** ![Purvaash](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/purvaash/32/22648_2.png) [@Purvaash](https://discourse.julialang.org/u/Purvaash)\
**Post date:** [December 12, 2023, 11:07am UTC](https://discourse.julialang.org/t/precompilation-error-loaderror-undefvarerror-printf-not-defined/107043/3 "2023-12-12T11:07:45Z")

</div>

Hi,

Thanks a lot for the suggestion @Fliks. Can you help me with where should I include `using Printf: @printf`? I had trouble finding where the modules of tn\_julia are defined. Is it the Project.toml file?

The contents of Project.toml are:

```julia
name = "tn_julia"
uuid = "53662e65-01d4-4314-8931-2bffaf2f7422"
authors = ["Marc Ritter <ritter.marc@physik.uni-muenchen.de>"]
version = "23.1.0"

[deps]
DecFP = "55939f99-70c6-5e9b-8bb0-5071ed7d61fd"
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

```

---

<div class="post-metadata">

**Author:** ![mritter](https://avatars.discourse-cdn.com/v4/letter/m/e274bd/32.png) [@mritter](https://discourse.julialang.org/u/mritter)\
**Post date:** [September 6, 2024, 9:19am UTC](https://discourse.julialang.org/t/precompilation-error-loaderror-undefvarerror-printf-not-defined/107043/4 "2024-09-06T09:19:15Z")

</div>

Hi! I’m the author of the `tn_julia` tutorial, sorry for this problem. I was recently made aware of this thread by a colleague.

I have now fixed the dependency file. If it is still useful for you, the exact same steps (see `README.md` in the tutorial) should now work after updating your repository. Tell me if that’s not the case.

---

<div class="post-metadata">

**Author:** ![Purvaash](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/purvaash/32/22648_2.png) [@Purvaash](https://discourse.julialang.org/u/Purvaash)\
**Post date:** [September 6, 2024, 12:56pm UTC](https://discourse.julialang.org/t/precompilation-error-loaderror-undefvarerror-printf-not-defined/107043/5 "2024-09-06T12:56:22Z")

</div>

‘git pull’ and following the same steps (readme file) fixed this issue. Thanks to your colleague for informing you of this! And thank you for creating and maintaining these nice tutorials!
