From d2603a452c578350adb5c4057b460071d24ddd01 Mon Sep 17 00:00:00 2001 From: Eli Holmes Date: Fri, 12 Apr 2024 17:03:50 -0700 Subject: [PATCH] add info on conda environments --- docs/posts/JHub-User-Guide.html | 33 ++++++++++++++++++++ docs/search.json | 12 ++++++- docs/sitemap.xml | 2 +- posts/JHub-User-Guide.Rmd | 55 +++++++++++++++++++++++++++++++++ 4 files changed, 100 insertions(+), 2 deletions(-) diff --git a/docs/posts/JHub-User-Guide.html b/docs/posts/JHub-User-Guide.html index d728c00..443830f 100644 --- a/docs/posts/JHub-User-Guide.html +++ b/docs/posts/JHub-User-Guide.html @@ -176,6 +176,7 @@

On this page

  • Let’s choose RStudio
  • Let’s choose JupyterLab
  • Stop your server
  • +
  • Using your own conda environment
  • @@ -278,11 +279,43 @@

    Tell Git who you ar

    Clone a Git repo

    Click the Git icon on the left and you can clone a repo.

    +

    You can also clone from the terminal with

    +
    cd ~
    +git clone <url to repo>

    Stop your server

    It will stop on it’s own after awhile, but if it hangs, you can stop it and restart it. With File > Hub Control Panel

    +
    +
    +

    Using your own conda environment

    +

    The following commands are entered in a terminal window.

    +

    Create a place in your home directory to keep your conda environments

    +
    cd ~
    +mkdir envs
    +

    Create the new environment and create a kernel for it. The environment must contain ipykernel (Python) or irkernel (R). Note use of -p instead of -n this is telling conda to create the environment in the current location and not the conda directory (which will be recreated every time the server restarts).

    +
    conda deactivate
    +conda create -p ~/envs/myenv numpy ipykernel
    +conda activate myenv
    +python -m ipykernel install --user --name myenv
    +

    You need to make sure that you run the ipykernel command when you are in the activated new environment.

    +

    Wait a few minutes and then the conda environment will appear on the launcher and in the dropdown in the kernels when you start a notebook.

    +

    If you want to use an environment.yaml file make sure it includes ipkernel (Python) or irkernel (R). Example:

    +
    name: myenv
    +channels:
    +  - conda-forge
    +dependencies:
    +  - numpy
    +  - ipykernel
    +

    With an environment.yaml file, the create command is

    +
    conda create -p ~/envs/myenv -f environment.yaml
    +

    To remove the conda environment and kernel:

    +
    conda deactivate
    +conda remove -p ~/envs/myenv
    +jupyter kernelspec remove myenv
    +

    You can see the kernels with

    +
    jupyter kernelspec list
    diff --git a/docs/search.json b/docs/search.json index f64bc95..a1a1b1b 100644 --- a/docs/search.json +++ b/docs/search.json @@ -481,7 +481,7 @@ "href": "posts/JHub-User-Guide.html#lets-choose-jupyterlab", "title": "JHub User Instructions", "section": "Let’s choose JupyterLab", - "text": "Let’s choose JupyterLab\nAny of the browser tabs with the Jupyter icon are JupyterLab.\nBe careful because you can be in RStudio with one GitHub repository and you could open the same repo in JupyterLab and easily create merge conflicts. Just be aware that they are in separate file systems so changes on RStudio will not be reflected in JupyterLab. It is not like you are on one computer.\n\nTell Git who you are\nBut I just did that with RStudio! I know but the JLab instance is in a different environment and doesn’t know what you did in the RStudio environment.\nOpen a terminal. You do this from the Launcher window. You can always open a new launcher window by clicking the little + tab\n\nNow click Terminal and run this code\ngit config --global user.name \"YourName\"\ngit config --global user.email \"your@email.com\"\ngit config --global credential.helper store\n\nCreate a PAT or use the one you created for RStudio\nMake a commit and push with the PAT as the password. Now you are set (until your PAT expires).\n\n\n\nClone a Git repo\nClick the Git icon on the left and you can clone a repo.", + "text": "Let’s choose JupyterLab\nAny of the browser tabs with the Jupyter icon are JupyterLab.\nBe careful because you can be in RStudio with one GitHub repository and you could open the same repo in JupyterLab and easily create merge conflicts. Just be aware that they are in separate file systems so changes on RStudio will not be reflected in JupyterLab. It is not like you are on one computer.\n\nTell Git who you are\nBut I just did that with RStudio! I know but the JLab instance is in a different environment and doesn’t know what you did in the RStudio environment.\nOpen a terminal. You do this from the Launcher window. You can always open a new launcher window by clicking the little + tab\n\nNow click Terminal and run this code\ngit config --global user.name \"YourName\"\ngit config --global user.email \"your@email.com\"\ngit config --global credential.helper store\n\nCreate a PAT or use the one you created for RStudio\nMake a commit and push with the PAT as the password. Now you are set (until your PAT expires).\n\n\n\nClone a Git repo\nClick the Git icon on the left and you can clone a repo.\n\nYou can also clone from the terminal with\ncd ~\ngit clone <url to repo>", "crumbs": [ "JHub User Guide" ] @@ -496,6 +496,16 @@ "JHub User Guide" ] }, + { + "objectID": "posts/JHub-User-Guide.html#using-your-own-conda-environment", + "href": "posts/JHub-User-Guide.html#using-your-own-conda-environment", + "title": "JHub User Instructions", + "section": "Using your own conda environment", + "text": "Using your own conda environment\nThe following commands are entered in a terminal window.\nCreate a place in your home directory to keep your conda environments\ncd ~\nmkdir envs\nCreate the new environment and create a kernel for it. The environment must contain ipykernel (Python) or irkernel (R). Note use of -p instead of -n this is telling conda to create the environment in the current location and not the conda directory (which will be recreated every time the server restarts).\nconda deactivate\nconda create -p ~/envs/myenv numpy ipykernel\nconda activate myenv\npython -m ipykernel install --user --name myenv\nYou need to make sure that you run the ipykernel command when you are in the activated new environment.\nWait a few minutes and then the conda environment will appear on the launcher and in the dropdown in the kernels when you start a notebook.\nIf you want to use an environment.yaml file make sure it includes ipkernel (Python) or irkernel (R). Example:\nname: myenv\nchannels:\n - conda-forge\ndependencies:\n - numpy\n - ipykernel\nWith an environment.yaml file, the create command is\nconda create -p ~/envs/myenv -f environment.yaml\nTo remove the conda environment and kernel:\nconda deactivate\nconda remove -p ~/envs/myenv\njupyter kernelspec remove myenv\nYou can see the kernels with\njupyter kernelspec list", + "crumbs": [ + "JHub User Guide" + ] + }, { "objectID": "posts/Set-up-centos-tljh.html", "href": "posts/Set-up-centos-tljh.html", diff --git a/docs/sitemap.xml b/docs/sitemap.xml index 0d32209..9cd2d9f 100644 --- a/docs/sitemap.xml +++ b/docs/sitemap.xml @@ -22,7 +22,7 @@ https://nmfs-opensci.github.io/nmfs-jhub/posts/JHub-User-Guide.html - 2024-03-31T15:57:05.124Z + 2024-04-13T00:03:11.894Z https://nmfs-opensci.github.io/nmfs-jhub/posts/Set-up-centos-tljh.html diff --git a/posts/JHub-User-Guide.Rmd b/posts/JHub-User-Guide.Rmd index 79a0469..d73893c 100644 --- a/posts/JHub-User-Guide.Rmd +++ b/posts/JHub-User-Guide.Rmd @@ -114,6 +114,61 @@ Click the Git icon on the left and you can clone a repo. ![](../images/user-guide/img6.png) +You can also clone from the terminal with +``` +cd ~ +git clone +``` + ## Stop your server It will stop on it's own after awhile, but if it hangs, you can stop it and restart it. With File \> Hub Control Panel + + +## Using your own conda environment + + +The following commands are entered in a terminal window. + +Create a place in your home directory to keep your conda environments +``` +cd ~ +mkdir envs +``` + +Create the new environment and create a kernel for it. The environment must contain `ipykernel` (Python) or `irkernel` (R). Note use of `-p` instead of `-n` this is telling conda to create the environment in the current location and not the conda directory (which will be recreated every time the server restarts). +``` +conda deactivate +conda create -p ~/envs/myenv numpy ipykernel +conda activate myenv +python -m ipykernel install --user --name myenv +``` +You need to make sure that you run the `ipykernel` command when you are in the activated new environment. + +Wait a few minutes and then the conda environment will appear on the launcher and in the dropdown in the kernels when you start a notebook. + +If you want to use an `environment.yaml` file make sure it includes `ipkernel` (Python) or `irkernel` (R). Example: + +``` +name: myenv +channels: + - conda-forge +dependencies: + - numpy + - ipykernel +``` +With an `environment.yaml` file, the create command is +``` +conda create -p ~/envs/myenv -f environment.yaml +``` + +To remove the conda environment and kernel: +``` +conda deactivate +conda remove -p ~/envs/myenv +jupyter kernelspec remove myenv +``` +You can see the kernels with +``` +jupyter kernelspec list +```