I was determined to use Julia on some bigger and more interesting coding missions several days ago. While the official Package Manager seems not always satisfying, and there are some little obstacles when adding a package. Wherever the problems come from, some confusions must be resolved before the next step.

### A LoadError When using A Package

Yes, it’s the NeareastNeighbors.jl. Normally you just need to type

julia> Pkg.add("NearestNeighbors")

And the package will automatically be added and all the “dependencies” will be solved.

Yes, of course it did. But when you are actually using it, the problem occurred.

julia> using NearestNeighbors
WARNING: could not import Distances.eval_reduce into NearestNeighbors
WARNING: could not import Distances.eval_end into NearestNeighbors
WARNING: could not import Distances.eval_op into NearestNeighbors
WARNING: could not import Distances.eval_start into NearestNeighbors
in include at ./boot.jl:261
in include at ./boot.jl:261


Well, it seems there’s something wrong with the package. It said it needs the latest Distances.jl package on its site, and it suggest us to checkout the latest version of Distances.jl. It’s not new enough!

julia> Pkg.checkout("Distances")


And nothing changes. I tried again and it still failed with the same error. After some analysis and experiment I found the problem lies in the version of the Distances.jl package.

### How to Make It “Right”

According to the Julia’s official document on Package Manager Functions and Package Manual, there are useful functions to help maintain the Julia packages on your machine. To see all installed packages, just type

julia> Pkg.installed()
Dict{ASCIIString,VersionNumber} with 18 entries:
"Blosc"             => v"0.1.4"
"JLD"               => v"0.5.6"
"NearestNeighbors"  => v"0.0.1"
"Conda"             => v"0.1.8"
"SHA"               => v"0.1.2"
"PyCall"            => v"1.2.0"
"Docile"            => v"0.5.19"
"ArrayViews"        => v"0.6.4"
"JSON"              => v"0.5.0"
"Devectorize"       => v"0.4.2"
"Compat"            => v"0.7.8"
"HDF5"              => v"0.5.6"
"Distances"         => v"0.2.1"
"FileIO"            => v"0.0.3"
"Dates"             => v"0.4.4"
"BinDeps"           => v"0.3.19"
"DistributedArrays" => v"0.1.6"
"URIParser"         => v"0.1.1"


which shows all installed packages and most importantly their current versions. The above is package list on my current machine. Obviously NearestNeighbors.jl thinks that Distances.jl’s version is still not new! And we have to replace/update it to a newer one. So we may type

julia> Pkg.update()


While nothing changes, it means everything is already the newest. And I tried using the NearestNeighbors.jl again. It failed with the same error again. What?!!

### Let’s Make It Even Much “Righter”

Well think of what is even much newer than the “newest”? The answer is those under development, those unpublished yet, which means we shall go find a dev version of the Distances.jl. On the git page of this package, I saw the latest dev version of Distances.jl, and well, let’s “install” it.

But first of all, the current version should be thoroughly removed.

julia> Pkg.rm("Distances")


And make sure there’s no folder named “Distances” in “~/.julia/v0.4/” (or v0.5, depends on your version) to clean it “thoroughly”. Then we may manually add packages not registered. Just type

julia> Pkg.clone("https://github.com/JuliaStats/Distances.jl.git")
INFO: Cloning Distances from https://github.com/JuliaStats/Distances.jl.git
INFO: Computing changes...
INFO: No packages to install, update or remove
INFO: Package database updated


And now the NearestNeighbors.jl works!

Finally let’s check the version of the packages.

julia> Pkg.installed()
Dict{ASCIIString,VersionNumber} with 18 entries:
"Blosc"             => v"0.1.4"
"JLD"               => v"0.5.6"
"NearestNeighbors"  => v"0.0.1"
"Conda"             => v"0.1.8"
"SHA"               => v"0.1.2"
"PyCall"            => v"1.2.0"
"Docile"            => v"0.5.19"
"ArrayViews"        => v"0.6.4"
"JSON"              => v"0.5.0"
"Devectorize"       => v"0.4.2"
"Compat"            => v"0.7.8"
"HDF5"              => v"0.5.6"
"Distances"         => v"0.2.1+"
"FileIO"            => v"0.0.3"
"Dates"             => v"0.4.4"
"BinDeps"           => v"0.3.19"
"DistributedArrays" => v"0.1.6"
"URIParser"         => v"0.1.1"


We see the version of Distances.jl changed from “0.2.1” to “0.2.1+”. It is newer than the “newest” indeed.

### Afterwords

Usually, adding unregistered packages is not suggested because this may raise some unknown and unstable problems. When Julia senses changes in packages being loaded, it would force a recompiling like

julia> using Distances
INFO: Recompiling stale cache file /home/joseph/.julia/lib/v0.4/Distances.ji for module Distances.


which means the module has changed.

Also if you want to force a precomile of some module, run

# force a recompile cache
Base.compilecache("JLD")


Finally I think we may just need to wait for a stable package, unless you are in badly need to use it.