Hi all! Just wondering if you would have a way to...
# questions
t
Hi all! Just wondering if you would have a way to use.
.ipynb
files in VSCode when having access to the catalog without getting the below "_undefined name catalog"_ error? I now selected the python exec in my
.venv
, but gives me this behavior. Thanks a lot in advance 🙂
Copy code
uv run python -m ipykernel install --user name --kedro-env --display-name "Kedro Environment"
creates a kernel successfully which i can select, but still does not work unfortunately
j
I always ask this to myself... hope that somebody can provide an answer! it's mildly annoying
y
@Juan Luis I think the challenge here is that you not only need the notebook to be connected to venv that has Kedro project and its dependencies, but also you need
kedro jupyter notebook
so that a session bootstraps
catalog
,
session
etc?
n
%load_ext kedro.ipython
If you want to use the correct kernel, make sure you have that in VScode settings. But for me just keeping
%load_ext kedro.ipython
as the top is an easier choice that always work.
The selection on Kernel is not that visible in VSCode, and in reality not too many people care/understand the difference between a ipykernel / conda env.
(Sorry I noticed I didn't read the question properly😅). I think the simple answer is Pylance (or whatever language server you are using for Python) is not aware of the namespace
A very long answer is https://github.com/microsoft/pylance-release/issues/3075 One way to fix this is to tell your Language server where to find these additional symbols. To do that you need to add a
typings/___builtins___.pyi
type stub.
🙌 1
j
☝🏼 thanks @Nok Lam Chan, that's helpful!
t
thanks a lot nok! does not seem to do the trick for me (yet) though..
n
If you are on VSCode, try to do
> Developer reload window
t
yes did that 🙂
contents of
__builtins__.pyi
should be empty right?
n
Ah, no
t
apologies 😅
n
no worries, I have no idea what this
pyi
file before today😅
_catalog_: str
_pipelines_: str
I have this just to silent the error, but you should give it the proper type hint
something like
Copy code
from kedro.io.data_catalog import DataCatalog
from kedro.framework.project import _ProjectPipelines

catalog: DataCatalog
pipelines: _ProjectPipeliens
t
ruff keeps complaining haha, i think i just let this one go 😞
thanks a lot for your help though!
copliot says i should do this:
Copy code
from kedro.framework.context import load_context

context = load_context('../')
catalog = context.catalog
but python does not agree
Copy code
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
ImportError: cannot import name 'load_context' from 'kedro.framework.context' 
(/Users/Thomas_dHooghe/repos/xxx/pricing-aa/.venv/lib/python3.12/site-packages/kedro/framework/cont
ext/__init__.py)
n
Python is right :)
^ruff, I tend to think it's a bug on
ruff
, the error of pylance disappear right after that. though, I have no idea if there are strong community consensus about the typing stub. But i know at least
mypy
also respect https://github.com/python/typeshed, so I tend to think it's a ruff problem.
🚀 1
🤯 1