You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Local imports do not work in native REPL - sys.path differs from cwd than expected #24361
Apologies for the mis-label. I indented to submit this issue as a bug, but was having issues with the Issue Reporter is VS Code, and I could not find a way to submit a bug directly via GitHub.
Behaviour
When using the new native REPL, importing from modules in the current workspace directory does not work.
For example, I have created a folder called test which has been opened in VS Code. This has a python file named script.py, which contains the line x=1.
test
├─ script.py
Attempting to import x from the script in the native REPL returns a ModuleNotFoundError.
os.getcwd() shows that the correct working directory has been set. Examining sys.path shows that the current workspace is not present.
Inserting the current workspace into sys.path using sys.path.insert(0, '') allows imports from local files to work as expected.
When using the terminal, imports work as expected, without the need to manually add the workspace directory to sys.path.
This makes the native REPL difficult to use, as you need to type sys.path.insert(0, '') at the beginning of every session, and is not consistent with the behaviour of the terminal.
Steps to reproduce:
Create a python file in the current working directory.
Assign a variable in this script and save it.
Open the native REPL and do from <file> import <variable>. This will fail.
It would be helpful if you could share directory structure too. There has been work done to set up the cwd for a single workspace directory as the project root itself: #23912 so you might be missing .vscode folder on your directory structure?? I would have to the directory structure honestly.
I am using a single workspace setup. In the example, there was no .vscode folder in the directory. Just the script inside the directory.
test
├─ script.py
I have tried adding a .vscode folder with a blank settings.json like below, but nothing seems to have changed, and the issue still occurs.
test
├─ .vscode
│ ├─ settings.json
├─ script.py
I opened this project as a Folder. By going File > Open Folder... and selecting this directory: C:\Users\hutch3232\Documents\python\finsim
I don't think this is using a Workspace - I don't have a .vscode folder in this project. Tested on python 3.12.8 as well. This definitely was working for me not that long ago.
I am experiencing the same issue. Upvote for a fix! Thank you!
import os
os.getcwd()
Shows that the Native REPL window CWD is indeed my project/ workspace root folder.
import sys
sys.executable
Shows that the Native REPL window python.exe is indeed the one from my projects .venv folder.
However, performing a local import of a function from a .py file and folder within my local workspace fails "out the box" with the error: ModuleNotFoundError: No module named ...
This is after the type hinting/ autocomplete recommended that the import would work!
The fix recommended above, to run this command:
sys.path.insert(0,'')
does work.
after running sys.path.insert(0,'') the local project imports work as expected! Thanks for that!
Activity
anthonykim1 commentedon Oct 31, 2024
Thanks for filing the issue and trying out the new native REPL :)
Have you set up your workspace in terms of https://code.visualstudio.com/docs/editor/workspaces#_singlefolder-workspace-settings ?
I wonder if you are on single or multi workspace scenario.
It would be helpful if you could share directory structure too. There has been work done to set up the cwd for a single workspace directory as the project root itself: #23912 so you might be missing .vscode folder on your directory structure?? I would have to the directory structure honestly.
ConorTosh commentedon Nov 1, 2024
I am using a single workspace setup. In the example, there was no .vscode folder in the directory. Just the script inside the directory.
test
├─ script.py
I have tried adding a .vscode folder with a blank settings.json like below, but nothing seems to have changed, and the issue still occurs.
test
├─ .vscode
│ ├─ settings.json
├─ script.py
Here is my user settings.json if this helps
github-actions commentedon Dec 2, 2024
Hey Anthony Kim (@anthonykim1), this issue might need further attention.
ConorTosh, you can help us out by closing this issue if the problem no longer exists, or adding more information.
ConorTosh commentedon Dec 2, 2024
The issue still exists. Please let me know what further information is needed.
hutch3232 commentedon Dec 7, 2024
I have the same issue as ConorTosh.
Printing
sys.pathin the native REPL vs. terminal REPL:I opened this project as a Folder. By going File > Open Folder... and selecting this directory: C:\Users\hutch3232\Documents\python\finsim
I don't think this is using a Workspace - I don't have a .vscode folder in this project. Tested on python 3.12.8 as well. This definitely was working for me not that long ago.
anthonykim1 commentedon Dec 9, 2024
Thanks for the directory structure ConorTosh , I'm going to update the label to be more appropriate to needing spike.
9 remaining items
simonh-tecex commentedon Jul 25, 2025
I am experiencing the same issue. Upvote for a fix! Thank you!
Shows that the Native REPL window CWD is indeed my project/ workspace root folder.
Shows that the Native REPL window python.exe is indeed the one from my projects .venv folder.
However, performing a local import of a function from a .py file and folder within my local workspace fails "out the box" with the error:
ModuleNotFoundError: No module named ...This is after the type hinting/ autocomplete recommended that the import would work!
The fix recommended above, to run this command:
sys.path.insert(0,'')does work.
after running
sys.path.insert(0,'')the local project imports work as expected! Thanks for that!Fix native REPL search path (microsoft#25372)
anthonykim1 commentedon Sep 11, 2025
Sorry for long wait folks, please try out the pre-release version of Python extension with vscode insiders: https://code.visualstudio.com/insiders/