Julia ArgumentError: Package RCall not found in current path: - julia

I just opened a new Jupyter notebook, and want to load some libraries.
using LinearAlgebra
using SparseArrays
using Statistics
using StatsBase
using RCall
Everytime I run the cell, I keep on getting the same error:
ArgumentError: Package StatsBase not found in current path:
- Run `import Pkg; Pkg.add("StatsBase")` to install the StatsBase package.
So I run the suggested commands:
import Pkg; Pkg.add("StatsBase")
I rerun the top cell, and I get a new error:
ArgumentError: Package RCall not found in current path:
- Run `import Pkg; Pkg.add("RCall")` to install the RCall package.
What I don't get is why I get these error messages, as have installed these packages previously. If I open one of my pre-existing Jupyter notebooks, whis in a different directory, this error does not occur. However, if I run Julia in terminal I get the same error. Seemingly it is working in some directories, and not others.
What may be causing the problem?

Julia can have many virtual environments. The Julia virtual environment has its own package installation state, independent from the global environment.
Contrary to Python, each environment just keeps links to a package repository in local hard drive rather than contain full copies of each package.
The environment is defined in the Project.toml file.
Simply run Pkg.status() to check which environment you are working currently with (this time it shows my global environment):
julia> Pkg.status()
Status `C:\JuliaPkg\Julia-1.6.1\environments\v1.6\Project.toml`
[6e4b80f9] BenchmarkTools v1.1.0
[1e616198] COSMO v0.8.1
[336ed68f] CSV v0.8.5
...
For Jupyter notebooks those are defined in the Project.toml that is located at the same folder as your notebook. This is most likely the source of your problems and the reason why you observe "strange" package installation states.
The Procet.toml file is normally created when you activate a folder:
julia> using Pkg
julia> Pkg.activate(".")
Activating new environment at `C:\SomeMyFolder\Project.toml`
However, when you run Jupyter (e.g. notebook(dir=".")) Pkg.activate(".") happens automatically where a Project.toml file is found in the current folder.

Related

How to import/add all packages in a julia project?

When I download a Julia library and try to execute the tests it gives the following message:
Got exception outside of a #test
LoadError: ArgumentError: Package OrdinaryDiffEq not found in current path:
- Run import Pkg; Pkg.add("OrdinaryDiffEq") to install the OrdinaryDiffEq package.
After that I run the required commands and the dependency gets installed. Now when I run the tests again it will show the same message just with another dependency.
Is there a way to add all of the Packages at once?
You can activate the test folder of that package (using Pkg; Pkg.activate("/that/path) and then run Pkg.instantiate().
This will download and build the pkg that you may missing and make you in the conditions to run the test.
Note: this should work for newer pkgs that use a separate Project.toml file for testing, not sure for old packages that still specify the dependencies used for test as a subsection of the main pkg Project.toml file.

Cannot install any package in Julia

I had used Julia some months back for a project, and didn't use it since. I hadn't faced problems back then. But now, I absolutely am not able to install any package.
(#v1.5) pkg> add Distributions
Resolving package versions...
ERROR: Unsatisfiable requirements detected for package Distributions [31c24e10]:
Distributions [31c24e10] log:
├─Distributions [31c24e10] has no known versions!
└─restricted to versions * by an explicit requirement — no versions left
Any package I install, I am getting the same error. How do I fix it?
This is the status of Pkg:
(#v1.5) pkg> status
Status `C:\Users\jaine\.julia\environments\v1.5\Project.toml`
[6e4b80f9] BenchmarkTools v0.5.0
[7073ff75] IJulia v1.21.2
[91a5bcdd] Plots v1.6.0
[438e738f] PyCall v1.91.4
[d330b81b] PyPlot v2.9.0
[2913bbd2] StatsBase v0.33.0
Given
├─Distributions [31c24e10] has no known versions!
it looks like you have a missing or corrupt package registry. The package manager will reinstall it for you if you delete .julia/registries and try to add the package again.
You can do this from within julia
rm(joinpath(homedir(), ".julia", "registries"), recursive=true, force=true)
These are indeed some of the more tricky situations to resolve so please bear with me as we work through this.
If you are not familiar with the basics of the package manager, it's worth a quick read to check out: https://julialang.github.io/Pkg.jl/v1/getting-started/
Assuming you are now in the Julia Repl, my general work flow for these issues is to remove everything it warns me about. The core problem here is that one of your existing packages is saying it needs a specific version of Distributions.jl but it's not able to add it. So, the first step would be to enter the pkg manager by doing ] and type rm Distributions.
Then, while still in the pkg mode, do resolve and add Distributions.
So the process is to just remove each package the Repl complains about until it stops complaining.
Note: If you run into something like this again, the worst-case scenario is to remove the project and manifest files for the specific Julia version you are using. If you navigate to ".julia/environments" you should be able to completely reset the Julia Env for a specific version there (that way you don't need to actually reinstall Julia).

Julia - Using development version of package in Jupyter Notebook

I'm working on a Package in Julia, and I created some functions and sent the pull request. I'm now waiting for it to be accepted in the master branch. In the mean time, I'd like to be able to use the package with the current functions I've just implemented in my Jupyter Notebook.
How can you use the development version of the package with your Jupyter Notebook?
Just tell Julia to use that package:
using Pkg
Pkg.develop(path=raw"C:\some_path\PackageName")
using PackageName
This will the package version from the given folder regardless of the current project settings.
When you want switch back to the main version:
Pkg.free(name="PackageName")
Note that this will work within a global package registry so this package version will be used across all Julia runs.
If you want to rather do it locally to the notebook just do
using Pkg, IJulia
notebook(dir=".") # select path to some empty directory
And then create a Jupyter notebook and type:
using Pkg
Pkg.activate(".")
Pkg.develop(path=raw"C:\some_path\PackageName")
This will create Project.toml file in the same directory where notebook is. When later opening the notebook just make sure Project.toml is in place - you will not need to call the command above again.

IJulia is not connecting to Jupyter Notebook

Whenever I try to open up a Jupyter notebook via Anaconda, I do not have a "Julia" code option. I have tried using Pkg., uninstalling Julia and Anaconda but my Mac does not seem to be connecting the two. I have also tried to open a Jupyter notebook directly from the Julia Kernel and that still is not working! I'm not sure what the issue is or what I should do next, here is the error:
(#v1.5) pkg> add "IJulia"
Updating registry at `~/.julia/registries/General`
######################################################################## 100.0%
Resolving package versions...
No Changes to `~/.julia/environments/v1.5/Project.toml`
No Changes to `~/.julia/environments/v1.5/Manifest.toml`
The output you showed is not an error. It is saying that IJulia is already installed in your system.
You need to run the notebook method from IJulia package.
Do:
julia> Using IJulia
julia> notebook()
If you don't have juypter already installed it prompt asking if you want to install it simply press y and it will start it in your browser automatically.
Also if for any reason it didn't open it automatically you can open it yourself.
Type localhost:8888(or you can click the link) in your browser url bar to open it.
What you posted does not indicate an error, it merely says that IJulia is already installed in your default environment: no changes were needed to add it.
You next step should now be to run:
julia> using IJulia
julia> IJulia.notebook()
After this, a new notebook should open in your browser.
I ever had an issue like this also. To solve this you need to rebuild the IJulia by run like below:
Using Pkg
Pkg.add("IJulia")
Pkg.build("IJulia")

How do you add Jupyter Notebook kernels for prior versions of Julia?

I am using a Windows machine and trying to have Jupyter Notebook kernels for multiple versions of Julia (0.7.0 and 1.1.1) because package AWS does not support the latest version, but does support 0.7.0.
I had Julia 1.1.1 installed on my computer first and got something similar to the following error when I tried to install package AWS: https://github.com/JuliaLang/Pkg.jl/issues/792
Then I installed Julia 0.7.0 and was able to install AWS in the Julia 0.7.0 terminal with Pkg.add("AWS") with no problems.
In the Julia 0.7.0 terminal, I installed IJulia again with Pkg.add("IJulia") and restarted my Jupyter notebook instance. Now I'd like to use AWS via Jupyter notebook but when I create a new one, only Julia 1.1.1 appears.
I ended up having success by showing which kernels I had using jupyter kernelspec list in terminal, which showed where my other Julia kernel was located.
>>> jupyter kernelspec list
Available Kernels:
julia-1.1 C:\Users\{%USERNAME%}\AppData\Roaming\jupyter\kernels\julia-1.1
python3 C:\ProgramData\Anaconda3\share\jupyter\kernels\python3
I navigated to the file path listed after julia-1.1
Created a julia-0.7 folder in that same directory
Copied over contents from the julia-1.1 folder
Edited the kernel.json file by replacing every instance of julia-1.1.1 with julia-0.7.0
What I ended up having success with seems like a very rudimentary way to solve this problem. I'd like a more elegant way to achieve the same result, similar to when adding multiple kernels for different versions of Python. (Using both Python 2.x and Python 3.x in IPython Notebook)
Please help, thank you!
You (probably) just need to Pkg.build("IJulia") on the second Julia version.
Since Julia 0.7 the package manager uses separate directories for each version of a package, meaning that, from the package managers perspective, the package is already installed, and no downloading or building is performed when you install the same version from a different Julia version. The package manager does not know, however, that IJulia needs to be rebuilt for this new Julia version. You can trigger the build manually by Pkg.build("IJulia").

Resources