Importing classes in JupyterNotebooks

22 Views Asked by At

I have a class system in one file and a file that uses it in another. They're both in the same folder. At the beginning of the file that uses the classes, I import the class file as well as both classes I need. Though the program runs and uses the classes correctly, VSStudio is underlining these imports in red and telling me that 'Import "filename" could not be resolved Pylance(reportMissingImports)'. I have no idea why this is happening, especially since it all compiles and runs correctly. Does anyone have any idea how I could fix this?

I've tried adding the classes to all, as well as using From filename import * instead of importing specific classes. I've also installed import_ipynb, so that's definitely not the issue (or at least, it really shouldn't be).

1

There are 1 best solutions below

2
aryaroop04 On

can you share your folder structure. and also the other folder should have the __init__.py file.

it should look something like this

other_folder
|___service
|       |_____package.py
|       |_____init__file.py
|___init__.py

working_folder
|___test.ipynb

in this ipynb file call the package by

from other_folder.service import package

this should be able to solve your problem