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

command not found when I try execute shell script in jupyter cell #9917

Closed
ztlevi opened this issue May 6, 2022 · 11 comments
Closed

command not found when I try execute shell script in jupyter cell #9917

ztlevi opened this issue May 6, 2022 · 11 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster

Comments

@ztlevi
Copy link

ztlevi commented May 6, 2022

Environment data

  • VS Code version: 1.67.0
  • Jupyter Extension version (available under the Extensions sidebar): 2022.4.1001271738
  • Python Extension version (available under the Extensions sidebar): 2022.6.0
  • OS (Windows | Mac | Linux distro) and version: Mac
  • Python and/or Anaconda version: python3.9
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): poetry
  • Jupyter server running: Local

Expected behaviour

image

Actual behaviour

image

Steps to reproduce:

[NOTE: Self-contained, minimal reproducing code samples are extremely helpful and will expedite addressing your issue]

This is due to my personal setup in zsh https://github.com/ztlevi/dotty-config/blob/652cff7fae4abadaa8016847933c71c235250b2d/env#L81

  • To reproduce, you'll probably need to set zsh as default terminal in macOS. Newer macOS already use zsh by default.
  • Add the following code to your zshrc
function _load_all() {
  mkdir -p $HOME/Downloads
  local topics=($(ls $HOME/Downloads))
}
_load_all

Logs

Output for Jupyter in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Jupyter)

info 17:27:20.562: Execute Cell 5 xxx.ipynb
info 17:27:21.148: Cell 5 executed with state Success

@ztlevi ztlevi added the bug Issue identified by VS Code Team member as probable bug label May 6, 2022
@github-actions github-actions bot added the triage-needed Issue needs to be triaged label May 6, 2022
@amunger
Copy link
Contributor

amunger commented May 6, 2022

thanks for the bug, not sure why that would be happening.

@greazer greazer assigned DonJayamanne and unassigned amunger May 9, 2022
@greazer
Copy link
Member

greazer commented May 9, 2022

Seems to possibly be related to #9682, @DonJayamanne, please check.

@greazer greazer added notebook-execution and removed triage-needed Issue needs to be triaged labels May 9, 2022
@DonJayamanne
Copy link
Contributor

@ztlevi
I've tested this at my end and this works as expected.
For some reason it looks like you have some shell thats sourcing the same .zshrc file.

Looks like this works as expected in Jupyter Notebook/Lab (based on your screenshot).
Please could you print the environment variables using

import os
os.environ

Print the values in both and compare them and see if there are any differences specific to the shell,
Please feel free to upload the contents of the two outputs and I'd be happy to look for the differences.

@DonJayamanne DonJayamanne added the info-needed Issue requires more information from poster label May 11, 2022
@ztlevi
Copy link
Author

ztlevi commented May 11, 2022

@DonJayamanne Compare side by side, left is the PATH print from vscode notebook, right is PATH print from jupyter notebook.

image

Left doesn't have /bin in the PATH where mkdir and ls located there. Furthermore, there are other bin paths missing. How is the PATH loaded in vscode notebook? Shouldnt' it use default $SHELL's PATH?

@DonJayamanne DonJayamanne removed the info-needed Issue requires more information from poster label May 16, 2022
@DonJayamanne
Copy link
Contributor

@ztlevi thanks for getting back with the information.
The path variables are inherited from the VS Code process. As you haven't launched vscode from a shell process, the environment variables are completely different.
Basically the vscode application (& other desktop applications) don't initialize any shell scripts and use any of the initialization shell scripts. Jupyter application on the other hand is launched from a terminal, hence the difference in the bahaviour and values of the path variable.

As a temporary work around you could:

  • Open your user settings.json file and add the following contents
  "jupyter.runStartupCommands": [
    "import sys",
    "sys.path.append('/bin')"
  ]

Please note, this is only a work around and we'll be looking into a more permanent fix as part of #9682

@ztlevi
Copy link
Author

ztlevi commented May 16, 2022

Thanks. This one doesn't work for me. I have to tweak a little bit.

  "jupyter.runStartupCommands": ["import os", "os.environ['PATH'] += os.pathsep+'/bin'"],

@DonJayamanne
Copy link
Contributor

@ztlevi
Please could you try the following:

  • Revert the changes to the runStartupCommands
  • Exit VS Code completely
  • Start VS Code & test this again to confirm whether it works or not.

Also, please could you provide the output from the Jupyter output panel (go into the command palette and select Jupyter: Show Output

@ztlevi
Copy link
Author

ztlevi commented Jun 30, 2022

Nice. it works!

@ztlevi ztlevi closed this as completed Jun 30, 2022
@ztlevi
Copy link
Author

ztlevi commented Feb 8, 2023

Reopening the ticket as this issue happen in latests Jupyter v2023.1.2010391206. VSCode version is 1.75.0

@ztlevi ztlevi reopened this Feb 8, 2023
@DonJayamanne
Copy link
Contributor

Please could you enable logging as follows:

  • Open settings & go into Jupyter->Logging
  • Change the value to verbose
  • Reload VS Code,
  • Attempt to repro the issue & then copy the output from the Jupyter output panel.

@DonJayamanne
Copy link
Contributor

Closing this issue as its been over 4 weeks, since the information was requested.
We'll be happy to reopen the issue when the requested information has been provided.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

4 participants