Skip to content
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

name '__file__' is not defined when using os/sys #6120

Open
danielreispereira opened this issue Jan 24, 2025 · 2 comments
Open

name '__file__' is not defined when using os/sys #6120

danielreispereira opened this issue Jan 24, 2025 · 2 comments
Labels
area: console Issues related to Console category. bug Something isn't working lang: python support
Milestone

Comments

@danielreispereira
Copy link

The following works fine on a clean VSCode :

import os 
import sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

But it fails on Positron with the following error

NameError: name '__file__' is not defined
Cell In[5], line 1
----> 1 sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
@lionel- lionel- added area: console Issues related to Console category. lang: python labels Jan 27, 2025
@lionel-
Copy link
Contributor

lionel- commented Jan 27, 2025

Could you please detail what you're doing exactly?

I can reproduce with executeCode (Cmd+Enter or Ctrl+Enter) but not with Run Python File (the arrow in the screenshot below):

Image

Ideally running line by line would produce the same effect as running the file but that is not always possible.

@juliasilge
Copy link
Contributor

juliasilge commented Jan 27, 2025

We suspect this may be related to work we've done on the working directory in the console.

In the console, there is no active __file__.

@juliasilge juliasilge added bug Something isn't working support labels Jan 29, 2025
@juliasilge juliasilge added this to the Future milestone Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: console Issues related to Console category. bug Something isn't working lang: python support
Projects
None yet
Development

No branches or pull requests

3 participants