-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Python cells are evaluated in the project or current working directory #3156
Comments
For Jupyter notebooks, we use the notebook's location as the working directory as of #2648. For regular Python scripts, I believe the current behavior is as intended. These scripts with code cells are kind of a special case. @seeM do you think we should make those behave more like full fledged notebooks? |
This is tricky! There are two parts:
Point 2 might need a fair bit of rewiring since we currently assume that there's only one console session per language. I don't think we can reuse notebook sessions for that since notebook sessions have different requirements e.g. they're intentionally disconnected from the console and plots panes since notebooks have their own UI for those, the matplotlib backend is also intentionally different, and I'm sure there's more. Maybe the current console session type is more of a "global console", and we could introduce a new "script console" session type for these? We'd need to iron out a bunch of details about the UX, like kernel selection, and navigating between consoles for the same language, which we haven't had to deal with yet. I'm curious to hear @jmcphers' thoughts too. |
I don't thing we should start entirely new sessions for these cells, because of all the complications @seeM pointed out. We really don't want a proliferation of sessions if we can avoid it. What if we did something as simple as just changing the working directory when you run a code cell from a script? |
Maybe #3188 is an even neater workaround? It would be more explicit than automatically changing the directory when running a code cell, which I think may be confusing for some users. |
Also relevant: microsoft/vscode-python#23656 (comment) |
This might be a good candidate for the new editor UI (toggle between project/current working directory). |
One option to consider is waiting on this until we have real multiple consoles as tracked in #3173; evaluating a code cell could spawn a new console in the directory of the |
We could also optionally provide this kind of functionality (spawn a new console in the file's directory) for |
This is related to #3155 but might be considered a bug, so I'm opening a separate issue.
Positron Version:
Positron Version: 2024.05.0 (Universal) build 1251
Code - OSS Version: 1.89.0
Commit: c0d8830
Date: 2024-05-15T13:58:23.111Z
Electron: 28.2.8
Chromium: 120.0.6099.291
Node.js: 18.18.2
V8: 12.0.267.19-electron.0
OS: Darwin arm64 23.4.0
Steps to reproduce the issue:
Create a project with the following structure:
In
main.py
, click "Run Cell` above the import statement. The sends the code to the Python Console, resulting in a ModuleNotFoundError:What did you expect to happen?
In VS Code, with the Jupyter extension, clicking on Run Cell sends the code to an interpreter (that yes, is tied to the script) where the code is evaluated in the script's parent directory.
Were there any error messages in the output or Developer Tools console?
N/A
The text was updated successfully, but these errors were encountered: