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 setting (other than .env) to append PYTHONPATH to kernel process #9564

Closed
2 tasks done
YoniChechik opened this issue Apr 3, 2022 · 7 comments
Closed
2 tasks done
Assignees
Labels
feature-request Request for new features or functionality

Comments

@YoniChechik
Copy link

Applies To

  • Notebooks (.ipynb files)
  • Interactive Window and/or Cell Scripts (.py files with #%% markers)

What happened?

Altough launch config exists, the PYTHONPATH is not added.

"launch": {
    "configurations": [
      {
        ...
        "cwd": "${fileDirname}",
        "windows": {
          "env": {
            "PYTHONPATH": "${fileWorkspaceFolder};${env:PYTHONPATH}"
          }

I know of the solution for .env files but this does not scale for multiple projects and is a specific file only to use jupyter-vscode which is not a great thing to add to a github repo with multiple users... I wish there was a way to add it to the configurations diractly. something like:

"jupyter.PYTHONPATH": "${fileWorkspaceFolder};${env:PYTHONPATH}"

Thanks for the great work :)

VS Code Version

latest

Jupyter Extension Version

latest

Jupyter logs

No response

Coding Language and Runtime Version

No response

Language Extension Version (if applicable)

No response

Anaconda Version (if applicable)

No response

Running Jupyter locally or remotely?

No response

@YoniChechik YoniChechik added bug Issue identified by VS Code Team member as probable bug needs-triage labels Apr 3, 2022
@DonJayamanne
Copy link
Contributor

DonJayamanne commented Apr 3, 2022

thanks for filling this issue, however i don't quite understand the feature. request here.

  • are saying that the PYTHONPATH in launch. json config is not used in jupyter?
  • if so, is this issue specific to interactive window or notebook or both
  • does the issue relate to debugging or regular execution of cells?

please note, when adding PYTHONPATH in . env files you can also use relative paths. would that address your requirements?

"jupyter.PYTHONPATH": "${fileWorkspaceFolder};${env:PYTHONPATH

don't quite understand this. today the current working directory is already in the current path.

@YoniChechik
Copy link
Author

  • are saying that the PYTHONPATH in launch. json config is not used in jupyter?

Yes.

  • if so, is this issue specific to interactive window or notebook or both

Both

  • does the issue relate to debugging or regular execution of cells?

Both

please note, when adding PYTHONPATH in . env files you can also use relative paths. would that address your requirements?

I wish to avoid the use of .env alltogether. Specifically your solution is only valid for vscode so this can be problematic to add to projects.

don't quite understand this. today the current working directory is already in the current path.

The example I've added was just a dummy example. for a more complex project where you wish to add other directories to the PYTHONPATH (e.g.: ${fileWorkspaceFolder}/src) this will have a problem.

@DonJayamanne DonJayamanne removed their assignment Apr 3, 2022
@DonJayamanne DonJayamanne added awaiting-community-thoughts and removed bug Issue identified by VS Code Team member as probable bug needs-triage labels Apr 3, 2022
@DonJayamanne DonJayamanne changed the title Add extra PYTHONPATH to kernel run Add setting (other than .env) to append PYTHONPATH to kernel process Apr 10, 2022
@greazer greazer added feature-request Request for new features or functionality and removed enhancement labels May 4, 2022
@DonJayamanne DonJayamanne self-assigned this Aug 15, 2022
@DonJayamanne
Copy link
Contributor

Unfortunately we haven't had enough upvotes to warrant adding such a change (feature) into the extension, hence closing this issue

@ndricca
Copy link

ndricca commented Aug 9, 2023

hi @DonJayamanne PYTHONPATH issues seem quite frequent inside the issues. do you think adding an extension setting like PyCharm "mark folder as source root" could be considered?

sorry if this is the wrong place to ask.
thanks

@DonJayamanne
Copy link
Contributor

DonJayamanne commented Aug 9, 2023

sorry if this is the wrong place to ask.

Please could you file a new issue with details of the issue

@ndricca
Copy link

ndricca commented Aug 9, 2023

I have no issue. I come from PyCharm where I can simply right-click on a folder and mark a directory as source root (i.e. add that folder to PYTHONPATH).
I have already solved editing my user settings.json but it looks more like a workaround. Any plans for a new feature to simplify this?

{
...
    "jupyter.runStartupCommands": [
        "%load_ext autoreload",
        "%autoreload 2",
        "import os, sys; sys.path.append('./src')  if os.path.isdir('./src') else ''"
        ]  
}

@DonJayamanne
Copy link
Contributor

rkaround. Any plans for a new feature to simplify this?

As mentioned, please file an issue, and if there are sufficient upvotes for such feature requestes, then we'll consider adding it.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests

4 participants