JupyterLab with Jupyter-AI initial setup and config

I have not used either before, and the last time I used python seriously was before virtual environments. I’m wanting to work on a few statistics projects that will mostly use r but a little python too. Since I’m disabled and have memory issues I liked the sound of Jupyter-AI to help keep me on track but I can’t find any info on the best way to configure it globally. If I try to install it as recommended on Getting Started - Jupyter AI I get warnings about no virtual environment.

> uv pip install jupyter-ai
error: No virtual environment found; run `uv venv` to create an environment, or pass `--system` to install into a non-virtual environment

and

❯ pip install jupyter-ai
error: externally-managed-environment

× This environment is externally managed
╰─> To install Python packages system-wide, try 'pacman -S
    python-xyz', where xyz is the package you are trying to
    install.
    
    If you wish to install a non-Arch-packaged Python package,
    create a virtual environment using 'python -m venv path/to/venv'.
    Then use path/to/venv/bin/python and path/to/venv/bin/pip.
    
    If you wish to install a non-Arch packaged Python application,
    it may be easiest to use 'pipx install xyz', which will manage a
    virtual environment for you. Make sure you have python-pipx
    installed via pacman.

note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.

But I was wanting to use Jupyter-AI across multiple projects that will each have their own virtual environment so I presume it would be better to have Jupyter-AI installed globally rather than for each venv. Is my thinking incorrect, and if not will I run into issues installing it with say uv --system pip install jupyter-ai?

And/or is there an entirely better way to go about this?

Manjaro Linux

I’ve been running a single environment with everything i need for a couple of years now on Archlinux. How i run it:

I have a mylab folder in my user home.
Inside of it i created a python venv by python -m venv lab.
I also put a requirements.txt into that folder with all things i want to install.

For example you could start like this:

jupyterlab
jupyterlab_ai

Now we activate our virtual environment by source lab/bin/activate and then pip install -r requirements.txt.

You can then start with jupyter lab and it should work.

Now doing all this venv business everytime you reboot get’s kinda annoying so i created a simple bash file (i called it jupyterlab.sh):

#!/bin/bash
source /home/myuser/mylab/lab/bin/activate

export SOME_ENVIRONMENT_VARIABLES=IF_NEEDED

cd /home/myuser/JupyterRoot
jupyter lab --no-browser

I also created the folder JupyterRoot in my home directory. This is where all my files/folders/notebooks will reside in.

Now also set chmod +x jupyterlab.sh. If you haven’t already you can deactivate the virtual environment by typing deactivate in the console.

The last thing i did was I created a systemd unit to start the lab everytime i start the computer.

I have put this simple unit into /home/myuser/.local/share/systemd/user/jupyter-lab.service (create the folders if not there already):

[Unit]
Description=Jupyter Lab
 
[Service]
WorkingDirectory=/home/myuser/JupyterRoot
ExecStart=/home/myuser/mylab/jupyterlab.sh
StandardError=append:/home/myuser/.log/jupyterlab.log
Restart=always
RestartSec=3
 
[Install]
WantedBy=default.target

You might need to create the .log folder in your home directory so the logfile can be created.
Then simply run systemctl --user start jupyter-lab.service and systemctl --user enable jupyter-lab.service.
If you want the lab to start even when the user does not log on you can enable lingering for your user (this only makes sense if you want the lab to be reachable for users or over the network).

Now if you want to install things with pip you can use the lab terminal or source into the lab venv. If you install pip packages remember to put them in the requirements.txt at some point the system python will be updated to a new major (once a year) and your environment will break. Just delete the lab venv. Create a new one with python -m venv lab, source into it and and reinstall with pip install -r requirements.

It seems very complicated when written down, but it really isn’t.

Over the years i created hundreds if not thousands of notebooks and over a hundred kernels for all kind of languages and weird things, all in that one huge environment:

Have fun!