Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing a ipykernel and running jupyter notebook inside a virtual env - not using conda

I've hit a dead end trying to solve/debug this issue which doesn't seem like it should be that difficult.

I'm working in Pycharm IDE (not the professional) and I'm working inside a virtual environment let's call it pythonProject and I want to be able to run launch a jupyter notebook in this environment so that it can pick up all the python packages i've installed and configured for this environment.

As I understand it from the documentation, these are the steps I need to take.

My terminal prompt statement:

(pythonProject) oliver@oliver-u20:~/pythonProject$

commands:

python3 -m pip install ipykernel
python3 -m pip install notebook
python3 -m ipykernel install --user --name pythonProject --display-name "Python (pythonProject)"
jupyter notebook

But when I load jupyter notebook, it only shows python3 under kernels.

I tried outputting jupyter kernelspec list And get only the base kernel which suggests from this that it's not finding my kernelspec, but I can't seem to figure from the documentation what i'm supposed to do.

Am I missing something?

like image 805
Oliver Farren Avatar asked Aug 31 '25 20:08

Oliver Farren


1 Answers

Ok so I've solved this.

I think there was an install issue with jupyter.

I tried reproducing this in a completely new project and venv and could get the kernel showing.

In the project and venv where I still couldn't, I noticed a discrepancy in the output of my jupyter --paths

In the working venv I could see under data /home/oliver/.local/share/jupyter Which is where the kernels I installed are located.

However in the project that wasn't working there was instead: /home/oliver/snap/jupyter/6/.local/share/jupyter

I'm guessing this snap path is from how I originally installed jupyter on my Ubuntu via the app store - seemed sensible at the time.

So I uninstalled jupyter, restarted my venv and the jupyter --paths has magically changed so that /home/oliver/.local/share/jupyter is present and when I start a jupyter notebook at the command line with jupyter notebook I can see all my kernels showing!

I found this quite difficult to debug with the documentation and command help outputs so hope someone else finds this useful.

like image 154
Oliver Farren Avatar answered Sep 04 '25 23:09

Oliver Farren