Pkg.precompile error when adding packages in project virtual environment (Julia)

Viewed 766

Coming from a Python background, I am now trying to learn Julia, so my problem may be related to my confusion between virtual environments between Python and Julia. In Julia, I experience difficulties adding packages into a project virtual environment. BUT I have no problems adding packages when I am not using a project environment, such as within REPL:

(@v1.6) pkg>add CSV

successfully adds the CSV package. However, when I activate my project environment (called self_learn) and try to add this same package into this environment, I see these error messages within REPL:

(@1.6) pkg> activate .
(self_learn) pkg> st
    Project self_learn v0.1.0
    Status `D:\Dropbox\Julia\self_learn\Project.toml` (empty project)
(self_learn) pkg> add CSV
  Resolving package versions...
    Updating `D:\Dropbox\Julia\self_learn\Project.toml`
  [336ed68f] + CSV v0.8.4
    Updating `D:\Dropbox\Julia\self_learn\Manifest.toml`
  [336ed68f] + CSV v0.8.4
  [9a962f9c] + DataAPI v1.6.0
  [e2d170a0] + DataValueInterfaces v1.0.0
  [82899510] + IteratorInterfaceExtensions v1.0.0
  [69de0a69] + Parsers v1.1.0
  [2dfb63ee] + PooledArrays v1.2.1
  [91c51154] + SentinelArrays v1.2.16
  [3783bdb8] + TableTraits v1.0.1
  [bd369af6] + Tables v1.4.2
  [2a0f44e3] + Base64
  [ade2ca70] + Dates
  [9fa8497b] + Future
  [b77e0a4c] + InteractiveUtils
  [8f399da3] + Libdl
  [37e2e46d] + LinearAlgebra
  [56ddb016] + Logging
  [d6f4376e] + Markdown
  [a63ad114] + Mmap
  [de0858da] + Printf
  [9a3f8284] + Random
  [9e88b42a] + Serialization
  [8dfed614] + Test
  [4ec0a83e] + Unicode
Precompiling project...
  Progress [>                                        ]  0/1
  ◑ self_learn
┌ Error: Pkg.precompile error
│   exception =
│    ArgumentError: Invalid header in cache file C:\Users\Admin\.julia\compiled\v1.6\self_learn\jl_A3B4.tmp.
│    Stacktrace:
│     [1] preferences_hash(cachefile::String)
│       @ Base .\loading.jl:1478
│     [2] compilecache(pkg::Base.PkgId, path::String, internal_stderr::IOBuffer, internal_stdout::Base.DevNull)
│       @ Base .\loading.jl:1337
│     [3] (::Pkg.API.var"#215#242"{IOBuffer, String, Base.PkgId})()
│       @ Pkg.API C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.6\Pkg\src\API.jl:1144
│     [4] with_logstate(f::Function, logstate::Any)
│       @ Base.CoreLogging .\logging.jl:491
│     [5] with_logger
│       @ .\logging.jl:603 [inlined]
│     [6] macro expansion
│       @ C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.6\Pkg\src\API.jl:1143 [inlined]
│     [7] (::Pkg.API.var"#212#239"{Bool, Vector{Task}, Pkg.API.var"#handle_interrupt#231"{Base.Event, ReentrantLock, Base.TTY}, Pkg.API.var"#color_string#229", Base.Event, Base.Event, ReentrantLock, Vector{Base.PkgId}, Vector{Base.PkgId}, Dict{Base.PkgId, String}, Vector{Base.PkgId}, Vector{Base.PkgId}, Dict{Base.PkgId, Bool}, Dict{Base.PkgId, Base.Event}, Dict{Base.PkgId, Bool}, Dict{Base.UUID, Pkg.Types.PackageEntry}, Vector{Base.PkgId}, Bool, Base.TTY, Base.Semaphore, String, Vector{String}, Vector{Base.PkgId}, Base.PkgId})()
  ◐ self_learn

(self_learn) pkg>

Adding other packages such as DataFrames and Pipe result in the same precompile errors. I have tried uninstalling and reinstalling Julia 1.6.1, but this issue persists. I am using Windows 10.

Any help will be appreciated.

1 Answers

The package cache for your module seems to be stalled. This hast most likely happened when you were installing packages for your module and hit Ctrl+Enter - the package repo usually does not survive situations too well.

Uninstalling Julia did not help because the package repo is held in a ~/.julia (or %HOME%\.julia on Windows) folder that lives independently of Julia installation.

What you need to do is just to delete the folder: C:\Users\Admin\.julia\compiled\v1.6\self_learn\ If this does not help you might need to install the entire C:\Users\Admin\ but this would require re-installation of all packages.

Related