Julia#1.0.0: How to get installed Pkg.uuid in REPL - julia

I want to use Base.compilecache.
It needs PkgId(UUID). But I don't know how to get installed Pkg.uuid in REPL.
https://docs.julialang.org/en/v1.0.0/base/base/#Base.compilecache
I tried Pkg.PackageSpec but can't get UUID.
https://docs.julialang.org/en/stable/stdlib/Pkg/#Pkg.PackageSpec
julia> using Pkg
julia> Pkg.status()
Status `~/.julia/environments/v1.0/Project.toml`
[8f4d0f93] Conda v1.0.1
[7073ff75] IJulia v1.9.3
julia> Pkg.PackageSpec("Conda")
PackageSpec(name=Conda)
julia> Pkg.PackageSpec("Conda").uuid
UUID("00000000-0000-0000-0000-000000000000")
My goal is to call Base.compilecache at Docker file.
Julia v0.6.4 code
julia -e "Base.compilecache(\"JSON\")"

You can use Base.identify_package("Conda").

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/.

environment variables for julia 1.0

I would like to have .julia under julia-1.0.0 directory so that I can copy entire julia installation to an offline machine.
what are the environment associated variables ? For 0.6 there used to be
JULIA_PKGDIR
JULIA_HOME
LD_LIBRARY_PATH
Tried setting these, still have an issue:
julia> LOAD_PATH
1-element Array{String,1}:
"/share/apps/Julia/julia-1.0.0/.julia/"
julia> DEPOT_PATH
1-element Array{String,1}:
"/share/apps/Julia/julia-1.0.0/.julia/"
julia> using Pkg
ERROR: ArgumentError: Package Pkg not found in current path:
- Run `Pkg.add("Pkg")` to install the Pkg package.
Stacktrace:
[1] require(::Module, ::Symbol) at ./loading.jl:817
JULIA_LOAD_PATH and JULIA_DEPOT_PATH. See the documentation of the new package manager.
your *_PATHs should have more entries:
> LOAD_PATH
3-element Array{String,1}:
"#"
"#v#.#"
"#stdlib"
> DEPOT_PATH
3-element Array{String,1}:
"/home/no/.julia"
"/home/no/.julia/julia-1.0.0/local/share/julia"
"/home/no/.julia/julia-1.0.0/share/julia"
It looks like you overwrote the default values and now julia cant find the other packages.
Also, (at least for my installation on ubuntu/wsl), if you just unpack the julia installation to a folder it'll do its magic there and you can copy that folder, ie .julia.

Can't open Llvm in ocaml

I'm trying to use llvm binding in ocaml, in my file test.ml, I have one line of code:
open Llvm
When I run the command
ocamlbuild -use-ocamlfind test.byte -package llvm
I get this result:
+ ocamlfind ocamldep -package llvm -modules test.ml > test.ml.depends
ocamlfind: Package `llvm' not found
Command exited with code 2.
Compilation unsuccessful after building 1 target (0 cached) in 00:00:00.
What did I do wrong in this? Thanks.
BTW, the _tag file contains:
"src": traverse
<src/{lexer,parser}.ml>: use_camlp4, pp(camlp4of)
<*.{byte,native}>: g++, use_llvm, use_llvm_analysis
myocamlbuild.ml contains:
open Ocamlbuild_plugin;;
ocaml_lib ~extern:true "llvm";;
ocaml_lib ~extern:true "llvm_analysis";;
flag ["link"; "ocaml"; "g++"] (S[A"-cc"; A"g++"]);;
I don't know why the instructions that you're using are so complex. You don't have to do anything like this to use llvm bindings in OCaml, provided you have installed them via opam.
Here is the recipe:
Install llvm bindings via opam.
it could be as simple as
opam install llvm
However, opam may try to install the latest version that is not available on your system, so pick a particular version, that you have and do the following (suppose you have llvm-3.8):
opam install conf-llvm.3.8
opam install llvm --criteria=-changed
(The -criteria flag will prevent opam from upgrading conf-llvm to the newest version)
Once it succeeds, you can easily compile your programs without any additional scaffolding.
Create and build your project
create a fresh new folder, e.g.,
mkdir llvm-project
cd llvm-project
create a sample application (borrowed from some tutorial, that I've found online):
cat >test.ml<<EOF
open Llvm
let _ =
let llctx = Llvm.global_context () in
let llmem = Llvm.MemoryBuffer.of_file Sys.argv.(1) in
let llm = Llvm_bitreader.parse_bitcode llctx llmem in
Llvm.dump_module llm ;
()
EOF
compile it for bytecode
ocamlbuild -pkgs llvm,llvm.bitreader test.byte
or to the native code
ocamlbuild -pkgs llvm,llvm.bitreader test.native
run it
./test.native mycode.bc

Julia : JLD package doesn't work when running Julia development version

The current version of Julia is 0.4.6. I, however, am running the development version 0.5. Suddenly JLD doesn't work. It's installed and updated. Yesterday I compiled code using JLD but this morning it doesn't work.
julia> using JLD
INFO: Precompiling module JLD...
WARNING: Method definition convert(Type{#T<:AbstractString}, AbstractArray{#S<:Union{Char, Int32, UInt32}, 1}) in module Base at unicode/utf32.jl:131 overwritten in module LegacyStrings at /root/.julia/v0.5/LegacyStrings/src/utf32.jl:133.
WARNING: Method definition isvalid(Array{Char, 1}) in module Base at unicode/utf32.jl:177 overwritten in module LegacyStrings at /root/.julia/v0.5/LegacyStrings/src/utf32.jl:179.
WARNING: New definition
string(Union{Char, LegacyStrings.UTF8String, LegacyStrings.ASCIIString}...) at /root/.julia/v0.5/LegacyStrings/src/utf8.jl:161
is ambiguous with:
string(Union{Char, UTF8String, ASCIIString}...) at unicode/utf8.jl:166.
To fix, define
string(Char...)
before the new definition.
WARNING: both LegacyStrings and Base export "UTF16String"; uses of it in module JLD must be qualified
ERROR: LoadError: LoadError: UndefVarError: UTF16String not defined
in include(::ASCIIString) at ./boot.jl:234
in include_from_node1(::ASCIIString) at ./loading.jl:417
in include(::ASCIIString) at ./boot.jl:234
in include_from_node1(::ASCIIString) at ./loading.jl:417
[inlined code] from ./boot.jl:237
in anonymous at ./<no file>:4294967295
in eval(::Module, ::Any) at ./boot.jl:237
[inlined code] from ./sysimg.jl:11
in process_options(::Base.JLOptions) at ./client.jl:239
in _start() at ./client.jl:318
while loading /root/.julia/v0.5/JLD/src/jld_types.jl, in expression starting on line 11
while loading /root/.julia/v0.5/JLD/src/JLD.jl, in expression starting on line 130
ERROR: Failed to precompile JLD to /root/.julia/lib/v0.5/JLD.ji
in error(::ASCIIString) at ./error.jl:21
in compilecache(::ASCIIString) at ./loading.jl:496
in compilecache(::Symbol) at ./loading.jl:485
in require(::Symbol) at ./loading.jl:355
in eval(::Module, ::Any) at ./boot.jl:237
When using the development version of Julia, you need to use the development versions of the packages (which works for packages where the developer keeps master up-to-date but hasn't tagged yet). If you run Pkg.checkout("JLD") to checkout master, JLD should work (works on my machine. Note you may need to Pkg.update() before checking out, and you may need to quit Julia and re-open it to recompile the new version).
But as a word of caution, don't use the development versions of Julia as a way to test things out. Remember, the language is still in alpha and there is no guarantee that the package ecosystem or Julia itself will work with the daily master. The dailies are good for working on the language and preparing packages for the next version (and being ballsy I guess).
Well, you're using Julia 0.5 which is still in development. If you switch to 0.4.6 then it should be fine. I'm using that and JLD works fine for me. You could also trying running Pkg.update() closing Julia, then reopening, to see if that helps.

how to find version number of Julia? Is there a ver() command?

I installed Julia studio 0.4.4, and found it does not support multi-line comments #=...=# so I wanted to find what version of Julia it is running.
In Matlab one types the command ver which not only shows the version number of matlab, but also the version numbers of all toolboxes installed.
I googled for sometime, but not able to find similar command for Julia. Is there such a command for Julia?
julia> Version
ErrorException("Version not defined")
julia> ver
ErrorException("ver not defined")
julia> ver()
ErrorException("ver not defined")
julia> Version()
ErrorException("Version not defined")
Just entering out the constant VERSION would also display the version number.
julia> VERSION
v"0.4.0"
Use the versioninfo command:
From the documentation:
versioninfo([verbose::Bool])
Print information about the version of Julia in use. If the verbose argument
is true, detailed system information is shown as well.
If you are using windows,you can use julia -version of the cmd command

Resources