How to install packeges (Python, R libraries) globally on the jupyterhub server (z2jh with kubes) so that all notebook users have access to them and can import and use them?

How to install packeges (Python, R libraries) globally on the server so that all notebook users have access to them and can import and use them?

I want to install just required packages on the server and then according to my enterprise security policies disconnect the server from internet so that become isolated and not getting hacked!(air gap server situation)

I have now jupyterhub running on the server with kubernetes & helm chart and microk8s (z2jh)…by the way do not want to install packages by adding it to notebooks images since each time a new user asks for library with different version i get force to recreate image and deploy through kubernetes…

tnx in advance for helping;
Javad

This generally means building a custom docker image that installs your packages.

See the user environment docs on specifying a custom image, and installing additional packages.

Hi @minrk
tnx for reply, I know about building my custom notebook image with desired libraries but do not want to do it since eveytime a user asks specific library I have to rebuild a new custom image…

the better way for me is making sth like local repository of downloaded libraries on the server and when a user wants a library just getting it from that repo since server is not connected to the internet…to put it other way, e.g. if I pip install “pyodbc” on the server or import it offline to the server, “pyodbc” package is being accessed globally by all the users…downloading library one time by the admin on the server and use it many times by users…

How can I do sth like that?

1 Like

You can also try running installs into a shared volume that you mount and put on $PYTHONPATH in containers, but I think installing in the image is a better approach if you want a package to be available to all users.

Building and publishing your images on CI can help a lot with the tedium of building and pushing after updating the image. We use chartpress to manage this process in various projects, including z2jh itself.

1 Like

I setup a folder to install R packages (R_library) and mount it as /library to the docker image when it runs in dockerspawner.
c.DockerSpawner.volumes = { R_library: { ‘bind’: ‘/library’, ‘mode’: ‘ro’ } }

Then I define in the image ENV R_LIBS_USER=/library
Alternatively you can use a file $HOME/.Rprofile with .libPaths(’/library’)

I suppose you can do a similar thing for kubernetes and for python with PYTHONPATH

2 Likes