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

Opening a notebook in browser does not appear to set up Python environment #13348

Closed
1 of 2 tasks
paladique opened this issue Apr 18, 2023 · 7 comments
Closed
1 of 2 tasks
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug triage-needed Issue needs to be triaged

Comments

@paladique
Copy link
Member

Applies To

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

What happened?

When opening up a notebook in a Codespace:

  • Virtual environment is not activated on initial launch, unless I open a second terminal. It activates if I stop the Codespace and open it again. (Seen in first image - terminal on the left is the initial terminal)
  • Kernel is not selected (Seen in both images)
  • Noticed when opening up a Codespace from these two repos

I do not encounter these issues when I open a notebook locally in VS Code.

codespace-notebook-env2

codespace-notebook-env

VS Code Version

Version: 1.77.3 Commit: 704ed70d4fd1c6bd6342c436f1ede30d1cff4710 Date: 2023-04-12T09:19:00.989Z Browser: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36 Edg/114.0.0.0

Jupyter Extension Version

v2023.3.1201040234

Jupyter logs

Visual Studio Code (1.77.3, codespaces, codespaces)
Jupyter Extension Version: 2023.3.1201040234.
Python Extension Version: 2023.6.1.
Workspace folder /workspaces/azureday-princeton
info 18:35:12.451: ZMQ loaded via fallback mechanism.
User belongs to experiment group 'jupyterEnhancedDataViewer'
User belongs to experiment group 'jupyterTest'
info 18:35:12.868: LSP Notebooks experiment is enabled
info 18:35:15.769: Process Execution: > ~/venv/bin/python -m pip list
> ~/venv/bin/python -m pip list
info 18:35:39.743: Starting Jupyter Session startUsingPythonInterpreter, .jvsc74a57bd0f2a18e7aa35240a52af99ab71370101fdc3f0f419f0b3683d6828ff1fe801d36./home/vscode/venv/python./home/vscode/venv/python.-m#ipykernel_launcher (Python Path: /home/vscode/venv, EnvType: Venv, EnvName: 'venv', Version: 3.10.10 (main, Mar 23 2023, 17:28:09) [GCC 10.2.1 20210110]) for '/workspaces/azureday-princeton/data-science-codespaces/notebook.ipynb' (disableUI=true)
info 18:35:39.789: Process Execution: > ~/venv/bin/python -c "import ipykernel; print(ipykernel.__version__); print("5dc3a68c-e34e-4080-9c3e-2a532b2ccb4d"); print(ipykernel.__file__)"
> ~/venv/bin/python -c "import ipykernel; print(ipykernel.__version__); print("5dc3a68c-e34e-4080-9c3e-2a532b2ccb4d"); print(ipykernel.__file__)"
info 18:35:39.834: Process Execution: > ~/venv/bin/python -m ipykernel_launcher --ip=127.0.0.1 --stdin=9003 --control=9001 --hb=9000 --Session.signature_scheme="hmac-sha256" --Session.key=b"c37269b3-5b7d-4484-a1c2-2aa9f51bdd3e" --shell=9002 --transport="tcp" --iopub=9004 --f=/home/vscode/.local/share/jupyter/runtime/kernel-v2-8363BGw0LfKZqOvG.json
> ~/venv/bin/python -m ipykernel_launcher --ip=127.0.0.1 --stdin=9003 --control=9001 --hb=9000 --Session.signature_scheme="hmac-sha256" --Session.key=b"c37269b3-5b7d-4484-a1c2-2aa9f51bdd3e" --shell=9002 --transport="tcp" --iopub=9004 --f=/home/vscode/.local/share/jupyter/runtime/kernel-v2-8363BGw0LfKZqOvG.json
info 18:35:39.834: Process Execution: cwd: /workspaces/azureday-princeton/data-science-codespaces
cwd: /workspaces/azureday-princeton/data-science-codespaces
info 18:35:40.563: ipykernel version & path 6.22.0, ~/venv/lib/python3.10/site-packages/ipykernel/__init__.py for /home/vscode/venv/bin/python
warn 18:35:42.062: StdErr from Kernel Process /home/vscode/venv/lib/python3.10/site-packages/traitlets/traitlets.py:2548: FutureWarning: Supporting extra quotes around strings is deprecated in traitlets 5.0. You can use 'hmac-sha256' instead of '"hmac-sha256"' if you require traitlets >=5.
  warn(

warn 18:35:42.062: StdErr from Kernel Process /home/vscode/venv/lib/python3.10/site-packages/traitlets/traitlets.py:2499: FutureWarning: Supporting extra quotes around Bytes is deprecated in traitlets 5.0. Use 'c37269b3-5b7d-4484-a1c2-2aa9f51bdd3e' instead of 'b"c37269b3-5b7d-4484-a1c2-2aa9f51bdd3e"'.
  warn(

info 18:35:42.353: ZMQ loaded via fallback mechanism.
info 18:35:42.398: Started Kernel venv (Python 3.10.10) (pid: 9194)
info 18:35:42.547: Process Execution: > ~/venv/bin/python ~/.vscode-remote/extensions/ms-toolsai.jupyter-2023.3.1201040234/pythonFiles/printJupyterDataDir.py
> ~/venv/bin/python ~/.vscode-remote/extensions/ms-toolsai.jupyter-2023.3.1201040234/pythonFiles/printJupyterDataDir.py

Coding Language and Runtime Version

Python v3.10.10

Language Extension Version (if applicable)

v2023.6.1

Anaconda Version (if applicable)

No response

Running Jupyter locally or remotely?

Remote

@paladique paladique added the bug Issue identified by VS Code Team member as probable bug label Apr 18, 2023
@alfredodeza
Copy link

We have a way to reproduce this with a public template . It is worth highlighting that Visual Studio Code in Codespaces is configured to have the default Python interpreter from the virtualenv. The behavior of not automatically selecting the kernel in the Jupyter Notebook is new. In previous releases it was automatically selected.

@DonJayamanne
Copy link
Contributor

In previous releases it was automatically selected.

With the new kernel picker, we do not default the kernels, the users are expected to select them, unless there is ever ONLY one Python environment and zero jupyter kernlespecs and zero remtoe jupyter servers.

@DonJayamanne
Copy link
Contributor

Thanks for filing this issue.

I do not encounter these issues when I open a notebook locally in VS Code.

Its likely you opened this notebook in the past and VS Code now remembers the kernel that was last used.
As mentioned earlier, with the new kernel picker, we no longer forcefully set the selected kernel, instead we expect users to select them. This is to get around the number of bugs we ran into with the Jupyter extension when trying to auto select a kernel (which was incorrect and users would hit a lot of errors when running a cell)
The new kernel picker enforces users to select a kernel when running a cell (thus passing on the responsibility of selecting a kernel to users, with the hope that users would select the right kernel as opposed to Jupyter extension trying to guess these things)

Virtual environment is not activated on initial launch, unless I open a second terminal. It activates if I stop the Codespace and open it again. (Seen in first image - terminal on the left is the initial terminal)

The Python extension is responsible for activation of the environment in the terminal, hence I would chase up this issue with the Python extension.
Hence transferring this issue to the Python extension

@DonJayamanne DonJayamanne transferred this issue from microsoft/vscode-jupyter Apr 18, 2023
@github-actions github-actions bot added the triage-needed Issue needs to be triaged label Apr 18, 2023
@DonJayamanne DonJayamanne transferred this issue from microsoft/vscode-python Apr 18, 2023
@alfredodeza
Copy link

In previous releases it was automatically selected.

With the new kernel picker, we do not default the kernels, the users are expected to select them, unless there is ever ONLY one Python environment and zero jupyter kernlespecs and zero remtoe jupyter servers.

Thanks for providing an explanation to the new behavior. In the context of an educational setting, it is error prone to ask students to make a selection when there are multiple Python interpreters available.
Understanding that automatically selecting the incorrect Python interpreter for the kernel, it would be useful if there was a way to configure this for the Notebook. That way, for environments like Codespaces where Visual Studio Code can be pre-configured for users, we can take advantage of automatically setting that for them.
Not having a way to pre-configure this is error-prone for students and it creates a burden on the maintainer of the devcontainer configuration or the person running a workshop or class.

@DonJayamanne
Copy link
Contributor

Got it, lets close this issue in favour of microsoft/vscode#130946

@mirekphd
Copy link

With the new kernel picker, we do not default the kernels, the users are expected to select them, unless there is ever ONLY one Python environment and zero jupyter kernlespecs and zero remtoe jupyter servers.

Was this design choice ever run though any kind of usability testing? I think a quick explanation of this choice is in order... What if you have to service a very long list of novice python users, each with a long list of Jupyter notebooks unseen by VS Code (such as auto-named output notebooks generated by papemill), combined with a long list of very similar kernels to scroll through?

@mirekphd
Copy link

What is also needed (apart from kernel auto-selection actually selecting preferred/single kernel automatically) is this kernel filtering / auto-selection to apply to python scripts (.py files) as well, where even basic python kernel filtering is not yet available.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 30, 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 triage-needed Issue needs to be triaged
Projects
None yet
Development

No branches or pull requests

5 participants