i’m working on visual studio code and can’t import files from the project’s folder
that’s the folder of the project
a code
import frame
is underlined on the word "frame" and produces following output:
Import "frame" could not be resolvedPylancereportMissingImports
i tried many things and solutions given on similar problems on SO, i checked global variable ComSpec, it’s value is proper – C:WINDOWSsystem32cmd.exe, i installed , i set "python.analysis.extraPaths"
to ["frame", "charts", "app"]
and gave value to python.defaultInterpreterPath
(its previous value was just ‘python’). what is interesting – i ahd no settings.json
value before, i created it myself by opening settings.json in visual studio code (i can’t edit settings.json when opened by using ctr+shift+p), copying contents and pasting it in file settings.json
which i created in .vscode
folder – it was not created by visual studio code although i’m using virtual environment
2
Answers
Edit:
Docs on Importing Jupyter Notebooks as Modules
Solution 1
I also found this other answer, using
import-ipynb
, that I’ll paste below:Solution 2
On the same question as linked above, there is this additional answer that could be helpful as well, I’ll paste it below:
Try turning the directory into a package by adding a
__init__.py
file. Here’s an example of how it would work:Directory Structure:
frame.py
:other.py
:__init__.py
:If you were to run
other.py
, you’d get:Heres a link to documentation on python’s import system
Simple and straightforward way is to convert your
frame.ipynb
file to.py
file.Also about the configuration of
"python.analysis.extraPaths"
. The scripts are all in the same folder, and"python.analysis.extraPaths"
does not need to be configured at this time.If subfolders exist, the configuration is as follows:
It is the path, not the file name
is the path, not the file name