0

I have a Python executable locally on my machine that has functionality/libraries not available for download in standard Python. I want to be able to import these libraries into JupyterLab, which I believe means changing the iPython kernel that JupyterLab is running on. It's not possible to launch Jupyter from the C:\ProgramData\ location where it is located.

My compiler/interpreter is currently in Anaconda:

import sys

print(sys.executable)

> C:\ProgramData\Anaconda3\python.exe

I want to add an iPython kernel using Python from a different source/path, currently:

C:\Program Files\IBM\SPSS\Statistics\27\Python3

This answer suggests adding a new kernel like this:

python -m ipykernel install --user --name <kernel_name> --display-name "<Name_to_display>"

but neither this answer (nor anywhere in the iPython documentation) does there seem to be an option to pull in Python from somewhere outside Anaconda in creating the new kernel. Is there a way to do this with a kernel, or a different way altogether?

My current workaround is to use %%script like this, but that limits the functionality to one cell and means the cell isn't really operating as a typical cell in a notebook anyway:

%%script C:\Program Files\IBM\SPSS\Statistics\27\Python3

Note: This is a specific approach to a more wide-ranging question regarding SPSS external mode here.

semblable
  • 773
  • 1
  • 8
  • 26

1 Answers1

1

The python -m ipykernel install --user implies registration at the user level. That is, it any Jupyter instance run by the user would check this registry and include it. Just make sure the python in this case in the external one you wish to use as a kernel.

merv
  • 67,214
  • 13
  • 180
  • 245
  • How do you make sure the `python` is the external one you want to use as a kernel? – semblable Mar 21 '22 at 21:49
  • 1
    @semblable check `where python`. In your case, might need to navigate (in command line) to `C:\Program Files\IBM\SPSS\Statistics\27\Python3` and then run the command. – merv Mar 22 '22 at 03:23
  • Running `python -m ipykernel install --user --name spss "spss"` from that directory, I get the following error: "ImportError: cannot import name 'constants' from partially initialized module 'zmq.backend.cython' (most likely due to a circular import) (C:\Program Files\IBM\SPSS\Statistics\27\Python3\zmq\backend\cython\__init__.py)." Note that I had to open Command Prompt in Administrator mode because the directory is in `C:\ProgramData`. – semblable Mar 24 '22 at 16:38