0

I'm using JupyterLab and I've found that it always uses my system's Python installation (version 3.9) instead of the installation of whatever conda environment I launch it from (3.10 in this case). Here is a minimal example of the problem:

In the terminal:

conda create --name Simplex python=3.10
conda activate Simplex
conda install jupyterlab
ipython kernel install --user --name=Simplex
jupyter lab

Hence JupyterLab has been launched in a conda environment with Python version 3.10, which I would have assumed means that the kernel would be using Python 3.10. However, when I run the following:

# Terminal Commands
!conda list python
!python -V

# Python Commands
import sys
print(f"Python Version {sys.version}")

The first query shows Python 3.10, but the others show Python 3.9. Furthermore, if I do something like int | str in a code block in JupyterLab, I'll get:

"TypeError: unsupported operand type(s) for |: 'type' and 'type'"

Since this functionality was added in Python 3.10, that serves as further confirmation that I am indeed using Python 3.9 unconsensually. The problem persists if I explicitly tell JupyterLab to use the kernel "Simplex" that I created in my minimal example. If I run:

print(f"{sys.executable}")

I get:

/Users/baileyandrew/opt/anaconda3/bin/python

whereas when poking around Finder I think that my conda environment's Python is stored at;

/Users/baileyandrew/opt/anaconda3/envs/Simplex/bin/python3.10

I am using a Mac, and conda -V gives the output conda 22.9.0.

I assume that there is an issue with either JupyterLab or Conda in how they are pathing to find my python distribution, but unfortunately I am woefully out of my depth here. Any help would be appreciated. Using 3.9 is not an issue for me, but I'd really like to get to the bottom of this issue.

BaileyA
  • 145
  • 1
  • 7

1 Answers1

0

Okay, I managed to solve this, thanks to the answer by CypherX on this question: Jupyter Lab and Notebook Problem: Kernel Error which is a distinct problem with a similar underlying cause. They specifically linked this resource which was also invaluable. To solve, I did the following:

# Terminal
jupyter kernelspec list

Which gave me the following kernels:

Available kernels:
  ir         /Users/baileyandrew/Library/Jupyter/kernels/ir
  simplex    /Users/baileyandrew/Library/Jupyter/kernels/simplex
  python3    /Users/baileyandrew/opt/anaconda3/share/jupyter/kernels/python3

It is the middle kernel that is relevant. I followed the filepath, and in the simplex folder is a file kernel.json.

Here are its contents:

{
 "argv": [
  "/Users/baileyandrew/opt/anaconda3/bin/python",
  "-m",
  "ipykernel_launcher",
  "-f",
  "{connection_file}"
 ],
 "display_name": "Simplex",
 "language": "python",
 "metadata": {
  "debugger": true
 }
}

The problem with this kernel is that it paths to the wrong python distro: /Users/baileyandrew/opt/anaconda3/bin/python. As mentioned in the question, by poking around in finder I had found that my correct distro was located at /Users/baileyandrew/opt/anaconda3/envs/Simplex/bin/python3.10. For anyone reading this question in the future, it should be pretty easy to find since the filepaths should be analogous.

After swapping the filepaths, I restarted my kernel (but I did not have to restart JupyterLab, although that wouldn't hurt). I made sure I was on the kernel called Simplex that I created in the minimal example above. Then, when running the code, it is clear that I am on Python 3.10.

sys.version works and so does int | str. !python -V reports Python 3.9, but I assume that is because the python command refers to the system distro instead of the environment distro. All in all, my problem appears to be solved.

BaileyA
  • 145
  • 1
  • 7