Table of Contents | ||
---|---|---|
|
...
Follow the instructions to launch jupyter. You should now be able to select the environment we just added:
...
Initiating a JupyterLab with your own Conda Environment (Any Python Version)
These instructions will outline how to start an interactive session on a compute node, load a conda environment with any version of python, and initiate a jupyter lab with that conda environment on that compute node. This task requires ssh tunneling and a conda environment that has jupyter lab installed. For more info on installing conda and setting up your conda environment, please see our other page, Miniconda Environment Setup.
Please note that you will need to install jupyter lab in your conda environment. The command for installing JupyterLab with conda can be found here.
These are the general steps.
Start an interactive session on the cluster. This is just the basic command I recommend for people trying to start an interactive session with 1 core. You can adjust this command to fit your needs. More info on flags can be found here.
Code Block srun -n 1 --mem=5G -p general --constraint=cpuonly --pty bash
Once you are allocated resources, then you’ll have to activate your conda environment. Replace “myenv” with the name of your environment.
Code Block conda activate myenv conda install ipykernel python3 -m pip install jupyterlab
Now use the
hostname
command to see what node you are on. Take note of what it says.Code Block hostname
Navigate to the folder where your data is. In jupyter lab, you can go into subfolders but you can’t go higher up in folders than where you started. Once you get where you want to be, initiate your jupyter lab.
Code Block jupyter-lab --no-browser --ip='*'
When you do that a whole bunch of stuff will pop up. It’ll look something like this:
We need to find two things in that mess, the name of the node and our port access number.
The name of the node is the same as the output “
hostname
" command we used earlier. In this case, the name of the node is cn506.Port access numbers are 4 digits long and normally start 88##. In this case, the port access number is 8888.
We now have to log in to the cluster a second time from a new terminal on your computer, but this time we’re going to log in directly to the node where our jupyter notebook was initiated and enable ssh tunneling. The command will look like this
ssh -NL localhost:8888:cn506:8888 netID@hpc2.storrs.hpc.uconn.edu
The only things you’ll have to update are your netID, the port access numbers, and the name of the node in the command above.
Sometimes in very rare instances, the port binding from the SSH tunnel command above might be denied due to a conflict within a conda environment and provide the following error message:
Code Block bind [127.0.0.1]:8888: Permission denied.
To fix the issue, it is recommended to remove and recreate the conda environment that is looking to be used. The Python packages within the Conda environment would need to be reinstalled. Once the environment is recreated and the Python packages reinstalled, the new Conda environment would have a clean state to launch Jupyter lab/notebook instances.
After you successfully log in to the node where your jupyter lab was initiated, you can copy the link that starts with numbers (127.0. etc.) and paste that into a browser. It should open a jupyter lab session that looks like the JupyterHub pictures above. From there you can click on the “Notebook” button to open a jupyter notebook or click on a previous notebook saved in your directory from the menu of your files on the left-hand side of the screen.
And from that notebook, you should be able to use your own conda environment. It should already be activated, but if it isn’t working you can look into installing nb_conda in all of your conda environments which allows users to switch between conda environments from within a jupyter notebook.
Note |
---|
If you get an error that says the port access number you requested is already in use, it may be because you have other Jupyter Notebooks running on your computer using those ports. In that case, you can specify a different (read: higher) port access number with the |