Goal: When using Jupyter how are python packages managed?
Where are Python Packages Installed During a Jupyter Session?
You can use pip list -v
and conda list
to inspect what is in your environment.
Example using the default Python kernel:
# Cell import sys print(sys.version)
3.12.3 | packaged by Anaconda, Inc. | (main, May 6 2024, 19:46:43) [GCC 11.2.0]
Notice there are two paths:
The library path of the conda environment that this default kernel is running from:
/apps/s/jupyterlab/miniconda3/lib/python3.12/site-packages
Your local home library path related to the version of Python within this kernel:
/home/salexan5/.local/lib/python3.12/site-packages
Can I pip install
?
Yes. And this will installed into your local home under the appropriate library/version folder.
# Before pip install: [salexan5@mblog2 ~]$ ls .local/lib/python3.12/site-packages/ dateutil numpy-2.0.0.dist-info __pycache__ pytz six-1.16.0.dist-info tzdata numpy numpy.libs python_dateutil-2.9.0.post0.dist-info pytz-2024.1.dist-info six.py tzdata-2024.1.dist-info
# Within Cell: pip install nltk
# After Installation: # Notice the new packages installed. [salexan5@mblog2 ~]$ ls .local/lib/python3.12/site-packages/ click joblib-1.4.2.dist-info numpy-2.0.0.dist-info pytz six-1.16.0.dist-info tzdata click-8.1.7.dist-info nltk numpy.libs pytz-2024.1.dist-info six.py tzdata-2024.1.dist-info dateutil nltk-3.8.1.dist-info __pycache__ regex tqdm joblib numpy python_dateutil-2.9.0.post0.dist-info regex-2024.7.24.dist-info tqdm-4.66.5.dist-info
Remember: Any previously install Python packages under this location will be available to your notebook.
Any installs/updates within the notebook will thus also affect any other Python environments you have that use this location and packages.
This could cause issues with dependencies and versions.
Can I Use Conda Within My Notebook?
Yes and no…
You can use conda
commands within cells to inspect and search.
You will not have permissions to conda install
since you do not own this folder, so do not have permissions to install/update anything within it.
But, you should have permissions if you have created the kernel, own it, and thus have permissions.
Jupyter Sessions
When you start a Jupyter session via OnDemand, you get a Session ID, which also creates a corresponding folder within your home:
Clicking on the Session ID link will open up a new tab:
Or, you can navigate to it via the command-line:
[salexan5@mblog2 ~]$ ls ondemand/data/sys/dashboard/batch_connect/sys/jupyter/form/output/8c0766ae-b302-47d7-8f40-007460cc3ad1/ after.sh before.sh config.py connection.yml job_script_content.sh job_script_options.json output.log script.sh user_defined_context.json
You can view the output.log
file under this folder to track the session.
Issue: Jupyter Doesn’t Start?
Sometimes when you try and start a Jupyter session it immediately fails to open.
This is typically caused by something that you have done/run/installed that has installed a python package under the library/version folder that is causing a dependency issue with a Python package installed under the kernel..
If you do not have the Session ID, then list the child session folders, in date order, under ~/ondemand/data/sys/dashboard/batch_connect/sys/jupyter/form/output/
and look at the output.log
file under the last child folder created:
[salexan5@mblog2 ~]$ ls -altr ~/ondemand/data/sys/dashboard/batch_connect/sys/jupyter/form/output/ ... drwxr-xr-x 2 salexan5 salexan5 4096 Aug 6 08:07 8c0766ae-b302-47d7-8f40-007460cc3ad1
Issue: Jupyter Doesn’t Start: Example
This example is from an older cluster/version of OnDemand, but the principle still applies.
The fakeusername
user had the following error:
Two things to notice.
First the ImportError
caused by a dependency issue: ImportError: cannot import name 'tarfile' from 'backports'
Second, the location of the package, that has been installed, where this is originating from: /home/fakeusername/.local/lib/python3.9/site-packages/pkg_resources
Unfortunately, the simplest way to resolve is to remove this folder.
How this effects your environment/pipeline you will have to figure out.
Unfortunately, the more complicated you try and make a single environment, the more likely this is too occur.
Suggestion: Maybe consider creating a separate Conda environment/kernel.
Prev | Workshop Home | Next |