Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Julia project specific environments (Project.toml) #1483

Open
cscheid opened this issue Jul 21, 2022 Discussed in #1482 · 7 comments
Open

Julia project specific environments (Project.toml) #1483

cscheid opened this issue Jul 21, 2022 Discussed in #1482 · 7 comments
Assignees
Labels
enhancement New feature or request julia
Milestone

Comments

@cscheid
Copy link
Collaborator

cscheid commented Jul 21, 2022

Discussed in #1482

Originally posted by tbeason July 21, 2022
There is some discussion on the Quarto guide about how to use various environments from R or Python. Right now, it seems that in order to use Julia code blocks I must keep any packages that I want to use in my global/default environment, rather than project specific ones. In Julia, this done by having a Project.toml file for the project (and perhaps a Manifest.toml also but not always needed).

When starting Julia you can call julia --project=Project.toml if it is in the current directory or you can start Julia normally and from the REPL type ] and then activate .

] activate .

or you can write

using Pkg
Pkg.activate(".")

I know that the last option would work if I added it to a (each?) code block, but is there a way to just add something to the quarto.yml file instead to use a Project.toml file for the whole project?

@cscheid cscheid added the enhancement New feature or request label Jul 21, 2022
@cscheid cscheid added this to the Future milestone Jul 21, 2022
@cscheid cscheid self-assigned this Jul 21, 2022
@cscheid
Copy link
Collaborator Author

cscheid commented Jul 21, 2022

We're using IJulia for our Julia execution engine. The IJulia guidance seems to be to add

using Pkg
Pkg.activate(".")

to the notebook. In Quarto, it'd be sufficient to add this once, to the very first code block. (All code blocks execute in the same "context")

I agree that it would be nice for different engines to configure settings like this, but we have to design this thoughtfully to avoid a proliferation of different option styles and conventions across different engines. This is a bigger change than just the Julia setting, so I don't have a concrete timeline for when we'll add this.

@tbeason
Copy link

tbeason commented Jul 21, 2022

If I am writing a book (in Quarto terminology), do I need to add those lines to a block in each .qmd file?

@cscheid
Copy link
Collaborator Author

cscheid commented Jul 21, 2022

Yes, you would. Each .qmd file executes independently of the other.

@Lightup1
Copy link

In my windows machine, it just start the Jupyter kernel in the current environment folder.
But I just find that run cell in my machine will not start a Jupyter console but a REPL of julia.

@camilogarciabotero
Copy link

camilogarciabotero commented Jan 18, 2023

Just to add some other behaviors of the Julia environments:

if Julia is installed via juliaup (which will become the de facto language version manager), then Julia resides in ~/.juliaup/bin/julia or in .julia/juliaup/<channel>/bin/julia (but this is fine right away and handled by IJulia Jupyer and Quarto), what I wanted to point is about the environments. So, Julia stores them in a accsesible dir (.julia/environments/) if created with the @ inside the REPL:

] activate @NewEnv

So that way one can always go to this env in the REPL without using any path. Note that, if there is no packages added, then the env, and therefore the dir, will be deleted.

Also, when initializing the julia REPL, it is easy to start with the desired NewEnv if it is already in the .julia/environments/ path, otherwise will create a new one in the same dir:

julia --project=@NewEnv

These behaviors bring me to the idea of having something like the following in the YAML:

title: test
jupyter: 
   julia-1.9:
      env: NewEnv

or something like:

title: test
engine:
    knitr:
      env: NewEnv  

or

title:
engine:
    jupyter:
       kernel: julia-1.9
       env: NewEnv

I guess the engine is not commonly used but seems like a good way to handle this.

@cderv
Copy link
Collaborator

cderv commented Mar 8, 2023

Posting here for reference a useful comment from Discussion related thread


The Julia project path may be specified by the environment variable JULIA_PROJECT, see https://docs.julialang.org/en/v1/manual/environment-variables/#JULIA_PROJECT.

Environment variables available at code block execution can be set in an _environment file, see
https://quarto.org/docs/projects/environment.html

Originally posted by @MHellmund in #1482 (comment)

@MHellmund
Copy link
Contributor

Let me just add:

  • The project environment where Julia starts must have the IJulia package installed.
  • You may add options to the kernel.json file installed for jupyter during the installation of IJulia. E.g., I use
Pkg.add("IJulia")
using IJulia
installkernel("Julia", "--optimize=0", "--project=@.") 

--project=@. means: search the current directory and its parents for Project.toml. If nothing is found, julia takes the global environment $HOME/.julia/environments/<version>/

@cderv cderv added the julia label Mar 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request julia
Projects
None yet
Development

No branches or pull requests

6 participants