Skip to content

Commit

Permalink
add info on conda environments
Browse files Browse the repository at this point in the history
  • Loading branch information
eeholmes committed Apr 13, 2024
1 parent 06d144a commit d2603a4
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 2 deletions.
33 changes: 33 additions & 0 deletions docs/posts/JHub-User-Guide.html
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ <h2 id="toc-title">On this page</h2>
<li><a href="#lets-choose-rstudio" id="toc-lets-choose-rstudio" class="nav-link" data-scroll-target="#lets-choose-rstudio">Let’s choose RStudio</a></li>
<li><a href="#lets-choose-jupyterlab" id="toc-lets-choose-jupyterlab" class="nav-link" data-scroll-target="#lets-choose-jupyterlab">Let’s choose JupyterLab</a></li>
<li><a href="#stop-your-server" id="toc-stop-your-server" class="nav-link" data-scroll-target="#stop-your-server">Stop your server</a></li>
<li><a href="#using-your-own-conda-environment" id="toc-using-your-own-conda-environment" class="nav-link" data-scroll-target="#using-your-own-conda-environment">Using your own conda environment</a></li>
</ul>
<div class="toc-actions"><ul class="collapse"><li><a href="https://github.com/nmfs-opensci/nmfs-jhub/edit/main/posts/JHub-User-Guide.Rmd" class="toc-action"><i class="bi bi-github"></i>Edit this page</a></li><li><a href="https://github.com/nmfs-opensci/nmfs-jhub/issues/new" class="toc-action"><i class="bi empty"></i>Report an issue</a></li><li><a href="https://github.com/nmfs-opensci/nmfs-jhub/blob/main/posts/JHub-User-Guide.Rmd" class="toc-action"><i class="bi empty"></i>View source</a></li></ul></div></nav>
</div>
Expand Down Expand Up @@ -278,11 +279,43 @@ <h3 class="anchored" data-anchor-id="tell-git-who-you-are-1">Tell Git who you ar
<h3 class="anchored" data-anchor-id="clone-a-git-repo">Clone a Git repo</h3>
<p>Click the Git icon on the left and you can clone a repo.</p>
<p><img src="../images/user-guide/img6.png" class="img-fluid"></p>
<p>You can also clone from the terminal with</p>
<pre><code>cd ~
git clone &lt;url to repo&gt;</code></pre>
</section>
</section>
<section id="stop-your-server" class="level2">
<h2 class="anchored" data-anchor-id="stop-your-server">Stop your server</h2>
<p>It will stop on it’s own after awhile, but if it hangs, you can stop it and restart it. With File &gt; Hub Control Panel</p>
</section>
<section id="using-your-own-conda-environment" class="level2">
<h2 class="anchored" data-anchor-id="using-your-own-conda-environment">Using your own conda environment</h2>
<p>The following commands are entered in a terminal window.</p>
<p>Create a place in your home directory to keep your conda environments</p>
<pre><code>cd ~
mkdir envs</code></pre>
<p>Create the new environment and create a kernel for it. The environment must contain <code>ipykernel</code> (Python) or <code>irkernel</code> (R). Note use of <code>-p</code> instead of <code>-n</code> 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).</p>
<pre><code>conda deactivate
conda create -p ~/envs/myenv numpy ipykernel
conda activate myenv
python -m ipykernel install --user --name myenv</code></pre>
<p>You need to make sure that you run the <code>ipykernel</code> command when you are in the activated new environment.</p>
<p>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.</p>
<p>If you want to use an <code>environment.yaml</code> file make sure it includes <code>ipkernel</code> (Python) or <code>irkernel</code> (R). Example:</p>
<pre><code>name: myenv
channels:
- conda-forge
dependencies:
- numpy
- ipykernel</code></pre>
<p>With an <code>environment.yaml</code> file, the create command is</p>
<pre><code>conda create -p ~/envs/myenv -f environment.yaml</code></pre>
<p>To remove the conda environment and kernel:</p>
<pre><code>conda deactivate
conda remove -p ~/envs/myenv
jupyter kernelspec remove myenv</code></pre>
<p>You can see the kernels with</p>
<pre><code>jupyter kernelspec list</code></pre>


</section>
Expand Down
12 changes: 11 additions & 1 deletion docs/search.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 \"[email protected]\"\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 \"[email protected]\"\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 &lt;url to repo&gt;",
"crumbs": [
"JHub User Guide"
]
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion docs/sitemap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</url>
<url>
<loc>https://nmfs-opensci.github.io/nmfs-jhub/posts/JHub-User-Guide.html</loc>
<lastmod>2024-03-31T15:57:05.124Z</lastmod>
<lastmod>2024-04-13T00:03:11.894Z</lastmod>
</url>
<url>
<loc>https://nmfs-opensci.github.io/nmfs-jhub/posts/Set-up-centos-tljh.html</loc>
Expand Down
55 changes: 55 additions & 0 deletions posts/JHub-User-Guide.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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 <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
```

0 comments on commit d2603a4

Please sign in to comment.