IJulia.jl icon indicating copy to clipboard operation
IJulia.jl copied to clipboard

Environment of a new notebook

Open yha opened this issue 3 years ago • 4 comments

It seems like creating a new notebook (File->New Notebook) starts it in the same environment as the last open notebook. I'm not sure if this is deliberate, but I find it a bit surprising & confusing (especially since there is no visual indication of the environment in the interface). I would expect a new notebook to be in the default environment, or perhaps in the same environment that notebook() was called from. ref #820

yha avatar Apr 19 '21 14:04 yha

IJulia starts notebooks in the environment of the directory where the project and manifest files are (or if they don't exist, in the default environment).

If you have two notebooks in the same directory, they will use the same environment. To circumvent this, just use multiple directories (you have to anyway to create different project and manifest files).

twavv avatar Apr 19 '21 14:04 twavv

IJulia starts notebooks in the environment of the directory where the project and manifest files are

I'm not sure what that means. Which project and manifest files? My understanding is that if you open an existing notebook, it looks in its directory (where the notebook file is) and its superdirectories, which is fine. My issue is with new notebooks that were not saved yet (so there is no notebook file). These seem to use the directory/environment of whatever notebook was last open, as far as I can tell.

yha avatar Apr 19 '21 14:04 yha

I think that was a typo -- I think I meant to say

Julia starts notebooks in the environment of the directory where the notebook is (or if the project and manifest files don't exist, in the default environment).

Sorry for that.

My issue is with new notebooks that were not saved yet (so there is no notebook file). These seem to use the directory/environment of whatever notebook was last open, as far as I can tell.

This is probably a JupyterLab behavior. The notebook files always exist (as far as I know) even if you haven't saved them yet (e.g., creating a new notebook will create a file on disk called "Untitled.ipynb" or whatever).

At the end of the day, IJulia is actually not even aware of the notebook files. From IJulia's (and IPython, IRKernel, etc.) perspective, it is started in a particular working directory and then just runs a server that speaks the Jupyter protocol in order to execute code (and the Jupyter protocol is just a fancy REPL - it has no idea about your notebook files).

If creating a new notebook starts it in the same directory as the previous notebook, that's just because Jupyter is spawning the Julia process in that directory. If that's the case, then this would be an upstream issue (with Jupyter Notebook or Jupyter Lab).

twavv avatar Apr 19 '21 20:04 twavv

When opening a new notebook with jupyterlab() or notebook(), the Untitled.ipynb file is opened in my home directory rather than in the directory from which the command was given (also where I have a Project.toml and Manifest.toml file which reference IJulia).

At the end of the day, IJulia is actually not even aware of the notebook files. From IJulia's (and IPython, IRKernel, etc.) perspective, it is started in a particular working directory and then just runs a server that speaks the Jupyter protocol in order to execute code (and the Jupyter protocol is just a fancy REPL - it has no idea about your notebook files).

This is still confusing because when running jupyter lab from e.g. an Anaconda prompt, the notebook is opened by Jupyter Lab with the root directory starting in the directory from which the command was issued. Calling the IJulia command juypterlab() should tell Jupyter where it's being called from so Jupyter can open a new notebook in that location.

A better default action would be equivalent to running: jupyterlab(dir=".") or notebook(dir=".")

thompsonmj avatar May 20 '21 15:05 thompsonmj