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

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
  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,
        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,
  2. The error I get is, 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

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,

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.

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.

1 Like

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:

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"

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.

1 Like

‘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!