Skip to content

Python cells are evaluated in the project or current working directory #3156

@gadenbuie

Description

@gadenbuie

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:

.
└── scripts
    ├── _one.py
    └── main.py
# scripts/_one.py
def hello_world():
    return "Hello, World!"
# scripts/main.py

# %%
from _one import hello_world
hello_world()

In main.py, click "Run Cell` above the import statement. The sends the code to the Python Console, resulting in a ModuleNotFoundError:

>>> from _one import hello_world
... hello_world()
ModuleNotFoundError: No module named '_one'
Cell In[1], line 1
----> 1 from _one import hello_world
      2 hello_world()

image

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.

image

Were there any error messages in the output or Developer Tools console?

N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions