question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

VSCode tries to install pip and ipykernel on WSL2 with venv and ipykernel already configured

See original GitHub issue

Version

Microsoft Windows [Version 10.0.22572.100]

WSL Version

WSL 2

Kernel Version

5.10.93.2

Distro Version

Ubuntu 20.04

Other Software

via pip ipykernel 6.9.2

VSCode February 2022 (version 1.65) Remote - WSL v0.64.2

Repro Steps

as described https://code.visualstudio.com/docs/datascience/jupyter-notebooks ran python3.9 -m venv .venv then in VSCode Ctrl+Shift+P selected the .venv/bin/python ensured Workspace Trust was given created a new .ipynb file and opened it in VSCode selected the kernel using the kernel picker in the top right and chose .venv/bin/python added print("works") to the cell, made sure it was a “Python” cell. Shift+Enter prompts to install ipykernel using pip, I clicked “install” and a terminal inside VSCode runs the commands and the output of these are below in the diagnostic logs.

I install ipykernel myself and the following packages were also installed;

Successfully installed asttokens-2.0.5 backcall-0.2.0 debugpy-1.5.1 decorator-5.1.1 entrypoints-0.4 executing-0.8.3 ipykernel-6.9.2 ipython-8.1.1 jedi-0.18.1 jupyter-client-7.1.2 jupyter-core-4.9.2 matplotlib-inline-0.1.3 nest-asyncio-1.5.4 parso-0.8.3 pexpect-4.8.0 pickleshare-0.7.5 prompt-toolkit-3.0.28 psutil-5.9.0 ptyprocess-0.7.0 pure-eval-0.2.2 pygments-2.11.2 python-dateutil-2.8.2 pyzmq-22.3.0 setuptools-60.9.3 six-1.16.0 stack-data-0.2.0 tornado-6.1 traitlets-5.1.1 wcwidth-0.2.5

As shown ipykernel-6.9.2 now exists in the cell Shift+Enter prompts to install ipykernel using pip again, and the exact same output in the diagnostic logs.

Expected Behavior

I have ipykernel installed and i have pointed VSCode to use the correct venv and correct kernel location. pip is installed so why is VSCode stuck on get-pip ?? I expect to just have the cell execute with this setup.

off topic; worth adding so it is not in any reply. Both a remote (in docker) Jupyter server AND using the host python/pip works just fine but both are not in-scope to this issue.

Actual Behavior

VSCode tried to install pip, and there is a setuptools issue related to the pip install already being complete. pip is available to VSCode in all other aspects of the VSCode+Python/Pylance operation, it is just when using Jupyter VSCode is mistaken in trying to install pip for no good reason. When that fails it is a red herring, VSCode should not be trying to install pip or the ipykernel in the first place.

This issue aims to have a python interpreter via the venv and the ipykernel installed into that venv (not in docker or on the host).

Diagnostic Logs

/home/wsl/bitbucket/.venv/bin/python /home/wsl/.vscode-server/extensions/ms-python.python-2022.2.1924087327/pythonFiles/shell_exec.py /home/wsl/bitbucket/.venv/bin/python /home/wsl/.vscode-server/extensions/ms-python.python-2022.2.1924087327/pythonFiles/get-pip.py /tmp/tmp-84767YuKhpR6lHjS.log
Executing command in shell >> /home/wsl/bitbucket/.venv/bin/python /home/wsl/.vscode-server/extensions/ms-python.python-2022.2.1924087327/pythonFiles/get-pip.py
/tmp/tmpe9vcmjw1/pip.zip/pip/_vendor/packaging/version.py:111: DeprecationWarning: Creating a LegacyVersion has been deprecated and will be removed in the next major release
/tmp/tmpe9vcmjw1/pip.zip/pip/_vendor/packaging/version.py:111: DeprecationWarning: Creating a LegacyVersion has been deprecated and will be removed in the next major release
/home/wsl/bitbucket/.venv/lib/python3.9/site-packages/_distutils_hack/__init__.py:17: UserWarning: Distutils was imported before Setuptools, but importing Setuptools also replaces the `distutils` module in `sys.modules`. This may lead to undesirable behaviors or errors. To avoid these issues, avoid using distutils directly, ensure that setuptools is installed in the traditional way (e.g. not an editable install), and/or make sure that setuptools is always imported before distutils.
  warnings.warn(
/home/wsl/bitbucket/.venv/lib/python3.9/site-packages/_distutils_hack/__init__.py:30: UserWarning: Setuptools is replacing distutils.
  warnings.warn("Setuptools is replacing distutils.")
Traceback (most recent call last):
  File "/home/wsl/.vscode-server/extensions/ms-python.python-2022.2.1924087327/pythonFiles/get-pip.py", line 27086, in <module>
    main()
  File "/home/wsl/.vscode-server/extensions/ms-python.python-2022.2.1924087327/pythonFiles/get-pip.py", line 144, in main
    bootstrap(tmpdir=tmpdir)
  File "/home/wsl/.vscode-server/extensions/ms-python.python-2022.2.1924087327/pythonFiles/get-pip.py", line 125, in bootstrap
    args = determine_pip_install_arguments()
  File "/home/wsl/.vscode-server/extensions/ms-python.python-2022.2.1924087327/pythonFiles/get-pip.py", line 67, in determine_pip_install_arguments
    import setuptools  # noqa
  File "/home/wsl/bitbucket/.venv/lib/python3.9/site-packages/setuptools/__init__.py", line 8, in <module>
    import _distutils_hack.override  # noqa: F401
  File "/home/wsl/bitbucket/.venv/lib/python3.9/site-packages/_distutils_hack/override.py", line 1, in <module>
    __import__('_distutils_hack').do_override()
  File "/home/wsl/bitbucket/.venv/lib/python3.9/site-packages/_distutils_hack/__init__.py", line 72, in do_override
    ensure_local_distutils()
  File "/home/wsl/bitbucket/.venv/lib/python3.9/site-packages/_distutils_hack/__init__.py", line 59, in ensure_local_distutils
    assert '_distutils' in core.__file__, core.__file__
AssertionError: /usr/local/lib/python3.9/distutils/core.py
Traceback (most recent call last):
  File "/home/wsl/.vscode-server/extensions/ms-python.python-2022.2.1924087327/pythonFiles/shell_exec.py", line 26, in <module>
    subprocess.check_call(shell_args, stdout=sys.stdout, stderr=sys.stderr)
  File "/usr/local/lib/python3.9/subprocess.py", line 373, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/home/wsl/bitbucket/.venv/bin/python', '/home/wsl/.vscode-server/extensions/ms-python.python-2022.2.1924087327/pythonFiles/get-pip.py']' returned non-zero exit status 1.

❯ pip --version
pip 22.0.4 from /home/wsl/bitbucket/.venv/lib/python3.9/site-packages/pip (python 3.9)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
DonJayamannecommented, Mar 30, 2022

again, VSCode should not try to install pip ever anyway, and if it actually just used the pip installed and callable there

The reason we’re trying to install pip is we’ve haven’t been able to install pip. We’ve found a number of instances where pip isn’t available hence we decided to install that and unblock the users. However that logic seems to be failing in your case.

That IS the whole output, the first thing it tries to do is install pip via python’s built in get-pip/py, and as explaine

Please confirm you are sending all of the output from here :

image

0reactions
DonJayamannecommented, Apr 25, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python requires ipykernel to be installed - Stack Overflow
I encounter an issue when I use the Jupyter Notebook in VS code. The screen shows " Python 3.7. 8 requires ipykernel to...
Read more >
Python projects with Poetry and VSCode Part 2
Start a new Python Project. poetry init, Create a pyproject.toml file interactively. poetry install, Install the packages inside the pyproject.
Read more >
How to Create a Perfect Machine Learning Development ...
How to Create a Perfect Machine Learning Development Environment With WSL2 on Windows 10/11 · 1. Uninstall existing installation (optional) · 2. Install...
Read more >
Python development using WSL 2 and Visual Studio Code
Now we have WSL2, but we need a Linux distribution to make it do anything useful. I installed Ubuntu 20.04. Again this requires...
Read more >
Python, pip, WSL 1 Debian Setup on Windows 10 1
Stayed with WSL 1 for now. I will wait for WSL 2 in a future upgrade. Tried Debian for this install. Installed Windows...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found