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

add ${workspaceFolder} to "PYTHONPATH" in launch.json by default #343

Open
Akopov4 opened this issue May 9, 2024 · 8 comments
Open

add ${workspaceFolder} to "PYTHONPATH" in launch.json by default #343

Akopov4 opened this issue May 9, 2024 · 8 comments
Labels
feature-request Request for new features or functionality needs community feedback

Comments

@Akopov4
Copy link

Akopov4 commented May 9, 2024

Hi, I'm new User of VScode. Previously I used Jetbrains Pycharm and not for a long time ago switched to VSCode.
Please add
"env": {
"PYTHONPATH": "${workspaceFolder};${env:PYTHONPATH}"
}
as default configuration parameters, when create to launch.json
Pycharm did it for a long time ago
Thank you in advance

@rchiodo rchiodo transferred this issue from microsoft/pylance-release May 9, 2024
@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label May 9, 2024
@rchiodo
Copy link

rchiodo commented May 9, 2024

Thanks for the issue. Pylance doesn't actually handle debugging of Python code. Transferring.

@karthiknadig
Copy link
Member

@Akopov4 You see an issue when you run or you see it with handling of imports in the editor?

@github-actions github-actions bot added the info-needed Issue requires more information from poster label May 9, 2024
@Akopov4
Copy link
Author

Akopov4 commented May 9, 2024

it's not an issue, it's feature request

@Akopov4
Copy link
Author

Akopov4 commented May 9, 2024

@karthiknadig

@github-actions github-actions bot removed the info-needed Issue requires more information from poster label May 9, 2024
@heejaechang
Copy link

"env": {
"PYTHONPATH": "${workspaceFolder}"
}

without it, when a user tries to run python file in debugger, import statement rooted from workspace root won't be resolved at runtime even if it is resolved at editing time due to our import resolve heuristic.

root/
        lib/
             __init__.py
             module.py
             currentfile.py

currentfile.py
import module # this will work at runtime and edit time
import lib.module # this won't work at runtime but will work at edit time.

user might want it to just work when debugging?

that said, if user run currentfile.py from terminal, it still won't work unless user add root to sys.path in some ways such as setting PYTHONPATH env var or sys.path.append(...) from code.

user could use .env for it to be set on terminal but when user run it in regular command line it won't work again.

but it will at least make it to just work for debugger?

@V4n1sh
Copy link

V4n1sh commented May 10, 2024

maybe "PYTHONPATH": "${workspaceFolder};${env:PYTHONPATH}", would be better for reason that there were already PYTHONPATH environmental variable set

@Akopov4
Copy link
Author

Akopov4 commented May 10, 2024

@heejaechang usually directories like .vscode, .idea and so on are included in gitignore file. So they don't affect production codes. This configuration is used by debugger and by "Run python file" in the editor. Soultion of @V4n1sh is better then my one

@karthiknadig karthiknadig changed the title add ${workspaceFolder} to "PYTHONPATH" in launch.son by default add ${workspaceFolder} to "PYTHONPATH" in launch.json by default May 13, 2024
@karthiknadig karthiknadig added feature-request Request for new features or functionality needs community feedback and removed triage-needed Needs assignment to the proper sub-team labels May 13, 2024
Copy link

Thanks for the feature request! We are going to give the community 60 days from when this issue was created to provide 7 👍 upvotes on the opening comment to gauge general interest in this idea. If there's enough upvotes then we will consider this feature request in our future planning. If there's unfortunately not enough upvotes then we will close this issue.

@karthiknadig karthiknadig transferred this issue from microsoft/vscode-python May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for new features or functionality needs community feedback
Projects
None yet
Development

No branches or pull requests

6 participants