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.
Related
I'm working with julia now, but some old version of code is deployed on julia 1.4.2, now I want to recheck the code but I don't want to switch between julia 1.6.3 (often used version) and 1.4.2. So I want to create a virtual env with conda, but now it seems that julia 1.4.2 is not available with conda. Any suggestions?
If you want to run more than one Julia version at a time you basically need to make sure that they use different location for package repositories (called depot path.
By default the folder used for depot path is ~/.julia (or %HOMEPATH%\.julia on Windows). If you start installing multiple Julia version you have a good chance to end up with a corrupted package repository.
Hence what you need is to set up the JULIA_DEPOT_PATH system variable - differently for each Julia version (see https://docs.julialang.org/en/v1/manual/environment-variables/).
For an example on my machine I have Julia 1.6.3 and Julia1.7.0rc2 and before starting either of them I run (Windows syntax this time):
set JULIA_DEPOT_PATH=c:\JuliaPkg\Julia1.6.3
or on Linux:
export JULIA_DEPOT_PATH=/home/ubuntu/Julia1.6.3/
This allows me to keep my package configurations separate.
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.
I created a new conda environment myenv and the only package I installed is the uncommon package astropy.
I ran jupyter notebook out of this activated environment myenv, just to see that myenv isn't activated and I need the package nb_conda to activate it, which I then installed.
Now its possible for me to select and activate myenv and to import the aforesaid package. However, if I switch to any other environment ("Change kernel"), then the package astropy is still loaded, eventhough it is not installed.
Now Im thinking that the kernel wasn't switched afterall. But this also cannot be, since it's not possible for myenvto load any other package of another environment.
What am I missing?
Cheers
EDIT 1: I just noticed: whenever I run the aforesaid package in the base (?) environment Python3, then a hidden directory .astropy is created in my home path C:\Users\me\. In this hidden directory I can see two .cfg-files. Maybe this all has something to do with my question?
Why at all is this hidden directory created? Does every python package create such a hidden folder?
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").
First let me preface this with the disclaimer that I'm new to R, but a longtime Python power user. Given that I love the conda ecosystem and the Jupyter notebook, I'm trying to set them up as my R development environment as well.
So using the instructions at: https://www.continuum.io/blog/developer/jupyter-and-conda-r I've set up a Jupyter Notbook that using an RKernel that should be hitting the installation of R installed in my Anaconda folder (I would think anyway).
Getting it setup was easy peasy and everything is working great for standard R stuff but my analysis requires some R libraries that are not available in r-essentials channel. No problem, I think I know how to install an R library. I go to "C:\Anaconda\R\bin\x64\Rgui.exe" and install rgdal, dismo, and some other packages. To check my work I looked in C:\Anaconda\R\library and there they are.
But when I run a jupyter notebook from the Anaconda command prompt. And start a new R notebook I get a "Error in library(dismo): there is no package called 'dismo'" Wait a sec, I run a ".libPaths()" from the notebook and it looks like its pointing
You can add .libPaths('path_where_your_packages_are') in a code cell at the beginning of your notebook to tell jupyter where your packages are. For me that was .libPaths('~/R/win-library/3.2') (work-around from discnerd who filed this issue on github).
To find out the path to your packages, just install a random package in R and wait for the location to be printed to the console.
More details (likely specific to my system/installations): When running .libPaths() in R, I got 2 locations: one for which admin rights were required for writing, and one for which admin rights were not required for writing. While packages installed through R land in the location where admin rights are not required, jupyter looks at the location where admin rights are required.
You can find out the path to your library with installed.packages()