0

What is a best practice for installing and running Jupyter Notebooks/Lab in Conda?

Starting with the assumption that it's a best practice to run your Python coding projects in separate environments:

Option 1: Should Jupyter be installed and run in the base Conda environment while selecting the sub-environment as a kernel from within Jupyter itself?

See argument for this way here: https://towardsdatascience.com/how-to-set-up-anaconda-and-jupyter-notebook-the-right-way-de3b7623ea4a

Notes: Having only one install would obviously save space on your computer. Though I believe you'd still have to install ipykernel into each environment for this way to work, per this answer: https://stackoverflow.com/a/53546634/1899063

Option 2: Or should it be installed separately each time you create a new environment (and thus run from that environment directly)?

See argument for this way here: https://towardsdatascience.com/get-your-computer-ready-for-machine-learning-how-what-and-why-you-should-use-anaconda-miniconda-d213444f36d6

That document is kind of long, so here is the relevant excerpt:

It’s a good idea at the start of every project to create a new project directory. Then within this directory, keep all of the relevant files for that project there, such as the data, the code and the tools you use... Doing it like this allows for an easy way to share your projects with others in the future.

Kristen G.
  • 705
  • 1
  • 8
  • 15
  • I had seen it stated as this in a now deleted (?!?) StackOverflow post [here](https://stackoverflow.com/questions/75283836/jupyter-notebook-with-conda-environment-cant-find-sklearn#comment132851693_75283836): "... one should not be installing Jupyter in every environment. Rather, see [this answer](https://stackoverflow.com/a/75089315/8508004). I.e., install ipykernel and keep jupyter + nb_conda_kernels in a separate environment, which is what should always be activated when launching Jupyter." – Wayne Aug 10 '23 at 15:58
  • @Wayne yeah, that definitely jibes with the first link I posted. I'm wondering if it just really depends on your use case. If it's critical to share an env with someone else, maybe you want to be installing things separately. But otherwise, this sounds like a much cleaner route to take – Kristen G. Aug 10 '23 at 17:17
  • Using `conda env export --no-builds` should produce something you can easily add Jupyter to the list in the `environment.yml` if you want to specify when sharing it to someone else. – Wayne Aug 10 '23 at 20:01

0 Answers0