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

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.

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

How include a file module in Julia 1.7?

My goal is: in Julia 1.7 on Mac with M1 processor I would include a module file with many functions inside.
I've tried to follow this thread to generate my own package
but it's generated an error.
I followed the answer but when i try importing MyPackage, Julia says: ArgumentError: Package MyPackage not found in current path.
With pwd() current path is Users/myname and in this folder MyPackage exists.
With command "import MyPackage" where i can see default folder for packages import ?
Where I get wrong ?
Sorry for my English.
I know two options here. Suppose I generated a package with the following file structure
MyPackage/
src/
MyPackage.jl
Project.toml
and MyPackage.jl is
module MyPackage
export greet
greet() = print("Hello World!")
end # module
Then there are two options, I know
Including of module MyPackage;
Embedding of package MyPackage into Julia's ecosystem.
Suppose, that pwd is MyPackage/
First option is
julia> include("src/MyPackage.jl")
Main.MyPackage
julia> using .MyPackage
julia> greet()
Hello World!
Notice the dot in using statement.
Second option
Start Julia REPL and enter pkg mode, then
(#v1.6) pkg> dev MyPackage/
Resolving package versions...
Updating `~/.julia/environments/v1.6/Project.toml`
[88e94d31] + MyPackage v0.1.0 `foo/bar/MyPackage`
Updating `~/.julia/environments/v1.6/Manifest.toml`
[88e94d31] + MyPackage v0.1.0 `foo/bar/MyPackage`
(#v1.6) pkg> st
Status `~/.julia/environments/v1.6/Project.toml`
[6e4b80f9] BenchmarkTools v1.3.1
[0772a1fa] CubicEoS v0.2.0
..........
[88e94d31] MyPackage v0.1.0 `foo/bar/MyPackage`
..........
[09ab397b] StructArrays v0.6.5
[a759f4b9] TimerOutputs v0.5.15
st command says that MyPackage became available in default environment.
Then you should be able to import/using the package. For the first time you should see precompiling message.
julia> using MyPackage
[ Info: Precompiling MyPackage [88e94d31-ecaf-41ca-ae10-053d89a189ff]
julia> greet()
Hello World!
P.S. The best place for local packages is .julia/dev/.

Expected the file `src/HijriConverter.jl` to exist for package `HijriConverter` at `…/HijriConverter.jl`

I am trying to add dependencies to a package that I am developing, but I get the following error:
(HijriConverter) pkg> add Parameters
Updating registry at `~/.julia/registries/General.toml`
Resolving package versions...
ERROR: expected the file `src/HijriConverter.jl` to exist for package `HijriConverter` at `/home/jafar_isbarov/Documents/projects/hijri/hijri-converter-julia-package/HijriConverter.jl`
Adding a file named HijriConverter to the src folder does solve the problem. I have two questions.
(1) Why do I need a file with the same name as the package? Is it supposed to have certain content?
(2) If I add that file, add dependencies, and delete the file afterwards, will that cause any problems?
Thanks.
To understand the minimal package requirements try running Pkg.generate as in code below:
julia> Pkg.generate("MyPackage")
Generating project MyPackage:
MyPackage\Project.toml
MyPackage\src/MyPackage.jl
Dict{String, Base.UUID} with 1 entry:
"MyPackage" => UUID("bad70bc4-3cf3-42bb-9f14-6b74ac64e2d7")
And here is the minimal file layout:
shell> tree /F
C:.
└───MyPackage
│ Project.toml
│
└───src
MyPackage.jl
And this is the generated module content with a single simple function:
shell> more MyPackage\\src\\MyPackage.jl
module MyPackage
greet() = print("Hello World!")
end # module
Further reading: https://pkgdocs.julialang.org/v1/creating-packages/

JuliaPro : ERROR: SystemError: unable to read directory Operation not permitted

JuliaPro - https://juliacomputing.com/products/juliapro/
I just get this Error with JuliaPro 1.5.2 - JupyterNote works fine -
MacBook Pro 2019 - Tried to uninstall and reinstall, but I'm not understanding why JuliaPro is giving me this error.
EDIT: Mac - Security & Privacy - Files and Folders - Atom all checked - JuliaPro-1.5.2.app - all checked
Full Disk Access - checked
Atom v0.12.23,
CSV v0.7.7,
DataFrames v0.21.8,
Glob v1.3.0,
IJulia v1.22.0,
JuliaDB v0.13.0,
Juno v0.8.4,
Pipe v1.3.0,
PkgAuthentication v0.3.0,
Weave v0.10.6,
Statistics
using Glob, CSV, Tables, DataFrames
fileDirectory = "/Users/Documents/CSV"
files = glob("*.csv", fileDirectory)
ERROR: SystemError: unable to read directory /Users/Documents/CSV: Operation not permitted
Stacktrace:
[1] readdir(::String; join::Bool, sort::Bool) at ./file.jl:780
[2] readdir at ./file.jl:775 [inlined]
[3] _glob!(::Array{String,1}, ::Glob.FilenameMatch{SubString{String}}) at /Users/.julia/packages/Glob/GOSfX/src/Glob.jl:399
[4] glob(::String, ::String) at /Users/.julia/packages/Glob/GOSfX/src/Glob.jl:367
[5] top-level scope at none:1
EDIT to Error: This shows up in Atom
Juno-julia-run
Argument to path.dirname must be a string
Object.dirname - /Applications/JuliaPro-1.5.2-1.app/Contents/MacOS/JuliaPro-Juno-1.5.2-1.app/Contents/Resources/JuliaPro-Juno-1.5.2-1/Contents/Resources/app.asar/src/electron-shims.js:9:10
- /Applications/JuliaPro-1.5.2-1.app/Contents/MacOS/JuliaPro-Juno-1.5.2-1.app/Contents/Resources/julia_atom_1.5.2-1/packages/JuliaRun-in-JuliaPro/lib/fs-utils.js:29:31
Generator.throw - null:null:null
step - /Applications/JuliaPro-1.5.2-1.app/Contents/MacOS/JuliaPro-Juno-1.5.2-1.app/Contents/Resources/julia_atom_1.5.2-1/packages/JuliaRun-in-JuliaPro/lib/fs-utils.js:41:273

Error while using LightGraphs to load a graph (xml.gz) in Julia

I am trying to load a network in the format xml.gz in Julia by using GraphIO.
The code is the following:
using LightGraphs
using GraphIO
D = loadgraphs("test.xml.gz", GraphMLFormat())
and I get the following error:
┌ Warning: `GraphIO.GraphMLFormat` has been moved to submodule `GraphIO.GraphML` and needs `EzXML.jl` to be imported first. I.e. use
│ using EzXML
│ GraphIO.GraphML.GraphMLFormat()
│ caller = top-level scope at test.jl:3
└ # Core ~/File/Code/test_graph/test.jl:3
ERROR: LoadError: UndefVarError: GraphML not defined
Then I have tried to import EzXML and do the following:
using LightGraphs
using GraphIO
using EzXML
r = GraphIO.GraphML.GraphMLFormat()
D = loadgraphs("test.xml.gz", r)
and I get the following error and I do not know how to fix it
┌ Warning: `GraphIO.GraphMLFormat` has been moved to submodule `GraphIO.GraphML` and needs `EzXML.jl` to be imported first. I.e. use
│ using EzXML
│ GraphIO.GraphML.GraphMLFormat()
│ caller = top-level scope at test.jl:5
└ # Core ~/File/Code/test_graph/test.jl:5
ERROR: LoadError: MethodError: no method matching bytesavailable(::Inflate.InflateGzipStream)
Closest candidates are:
bytesavailable(!Matched::Base.SecretBuffer) at secretbuffer.jl:153
bytesavailable(!Matched::Base.Filesystem.File) at filesystem.jl:198
bytesavailable(!Matched::Base.BufferStream) at stream.jl:1243
...
There seems to be something wrong with decompression - I can't tell you why but I could also reproduce with other zipped graphs.
Consider unzipping the graph (with gzip on linux for example):
gzip -c -d test.xml.gz > test.xml
Then you should be able to load it with
D = loadgraph("test.xml", GraphIO.GraphML.GraphMLFormat())

How to run a Julia project?

Julia is not in my wheelhouse yet, but I have been handed a Julia project to run the code within.
This consists of a directory containing a main.jl, a Project.toml and a Manifest.toml.
I've read up a little on what the TOML files are for; to summarise my current understanding, they form a project or environment (not sure which, or what the real difference is).
I have installed Julia v1.3.1 at the command line by downloading the tar, decompressing and placing in my path. Typing julia at the command line opens the Julia CLI REPL as expected.
I have tried to run the code by using julia main.jl, this results in complaints about the required packages not being present, e.g.:
julia main.jl
ERROR: LoadError: ArgumentError: Package JSON not found in current path:
- Run `import Pkg; Pkg.add("JSON")` to install the JSON package.
Stacktrace:
[1] require(::Module, ::Symbol) at ./loading.jl:887
[2] include at ./boot.jl:328 [inlined]
[3] include_relative(::Module, ::String) at ./loading.jl:1105
[4] include(::Module, ::String) at ./Base.jl:31
[5] exec_options(::Base.JLOptions) at ./client.jl:287
[6] _start() at ./client.jl:460
in expression starting at /home/<user>/myproject/main.jl:3
I can follow the instructions here and load the required packages, but surely I shouldn't do this manually for every package?
As every package required is listed in the Project.toml I guess there should be some way to tell Julia to make sure the packages in the project are made available (I'm thinking something along the lines of Python's requirements file).
I have tried julia --project=main.jl, but this just results in the REPL loading again with nothing happening (not sure if any project or environment is loaded or not).
How can I tell Julia to run the script in this project while taking note of the requirements and other information in the TOML files?
Update:
Have figured out to enter ] at the REPL to enter the pkg package manager. Then I can:
(v1.3) pkg> activate .
Activating environment at `~/myproject/Project.toml`
(myproject) pkg> instantiate
(myproject) pkg>
Then leave the manager by pressing backspace.
Still not sure how to "run" everything though.
You’re very close to the solution! If the files are all in a directory dir then the command would be
julia --project=dir main.jl
You could also start an interactive session in that environment and then run the code in the file via
julia --project=dir
julia> include(“main.jl”)
Edit: If the directory is the current working directory, then you can just use --project=.
The error message Package JSON not found in current path imply that you don't have JSON installed.
You can check this by starting Julia and type using JSON
To install JSON all you have to do is writing import Pkg; Pkg.add("JSON")
See this output for example:
$ julia
_
_ _ _(_)_ | Documentation: https://docs.julialang.org
(_) | (_) (_) |
_ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 1.5.2 (2020-09-23)
_/ |\__'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |
julia> using JSON
ERROR: ArgumentError: Package JSON not found in current path:
- Run `import Pkg; Pkg.add("JSON")` to install the JSON package.
Stacktrace:
[1] require(::Module, ::Symbol) at ./loading.jl:893
julia> import Pkg; Pkg.add("JSON")
Updating registry at `~/.julia/registries/General`
Updating git-repo `https://github.com/JuliaRegistries/General.git`
Resolving package versions...
Updating `~/.julia/environments/v1.5/Project.toml`
[682c06a0] + JSON v0.21.1
Updating `~/.julia/environments/v1.5/Manifest.toml`
[682c06a0] + JSON v0.21.1
[69de0a69] + Parsers v1.1.0
[ade2ca70] + Dates
[a63ad114] + Mmap
[de0858da] + Printf
[4ec0a83e] + Unicode
julia> using JSON
[ Info: Precompiling JSON [682c06a0-de6a-54ab-a142-c8b1cf79cde6]
julia>

Resources