Solved

Python SDK using poetry

  • 2 March 2023
  • 5 replies
  • 137 views

Badge +2

I have cloned the following in my local DEV folder.

using-cognite-python-sdk.git

I have also installed the dependencies that are defined in the pyproject.toml in the repo.

To run the code in jupyter notebooks. (Note: Change the "Kernel" to use the virtual environment created by poetry.) and add new libraries as needed.

 

How do I change the Kernel in jupyter notebook to the one created by poetry? When I open the jupyter notebook from the repo folder, it shows the general python3 (ipykernel) but this was present even before I installed poetry. 

So how do I change the kernel in my notebook.

 

Please advise.

 

icon

Best answer by Kristian Gjestad Vangsnes 3 March 2023, 09:26

View original

5 replies

Userlevel 2

Hi @eashwar11, if you have installed poetry and ran `poetry install`, have you activated the environment? if so, can you try installing the ipykernel directly : poetry run python -m ipykernel install --user --name myname ?

Badge +2

Thanks @Kristian Gjestad Vangsnes . I can see the environment is activated (as shown below in BLUE). But when i try to install ipykernel directly, it is giving the following messages (highlighted in yellow). I am trying to clone the extractor-utils repo and work to create a custom extractor in my local.

D:\pycdf\python-extractor-utils-master\python-extractor-utils-master>poetry env list
cognite-extractor-utils-yeiQVxSK-py3.9 (Activated)

D:\pycdf\python-extractor-utils-master\python-extractor-utils-master>poetry run python -m ipykernel install --user --name eashwar_n
C:\Users\eashwar_n\AppData\Local\pypoetry\Cache\virtualenvs\cognite-extractor-utils-yeiQVxSK-py3.9\Scripts\python.exe: No module named ipykernel

Userlevel 2

Thank you @eashwar11! Can you try to add ipykernel by running

poetry add ipykernel

and then run ‘poetry run python -m ipykernel install --user --name myname’ again?

Badge +2

Great! It worked now. I added the ipykernel and then ran the above command. After launching the jupyter notebook, I could see the new env with <myname> showing up in the notebook.

Thanks a lot!

Userlevel 2

No problem @eashwar11, thank you for reaching out! We will make sure that the documentation is updated.

Reply