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

"Run Cell" does not pickup on jupyter installed via virtualenv but conda works #3801

Closed
sotte opened this issue Nov 14, 2018 · 12 comments
Closed
Assignees

Comments

@sotte
Copy link

sotte commented Nov 14, 2018

Environment data

  • VS Code version: 1.29.0 5f24c93878bd4bc645a4a17c620e2487b11005f9 x64

  • Extension version (available under the Extensions sidebar): 2018.10.1

  • OS and version: Ubuntu 18.04

  • Python version (& distribution if applicable, e.g. Anaconda): pipenv with python 3.7

  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): virtualenv

  • Relevant/affected Python packages and their versions: -

Actual behavior

When using a virtualenv/pipenv environment clicking on "Run Cell" yields the error msg:
Running cells requires Jupyter notebooks to be installed.

(But it works with conda.)

Expected behavior

Cell is executed.

Steps to reproduce:

mkdir hello
cd hello
pipenv --python 3.7
pipenv shell
pipenv install jupyter
which jupyter
# /home/somebody/.local/share/virtualenvs/hello-UXM3mEkX/bin/jupyter
# jupyter notebook also works on its own

Open vscode, select the interpreter for the "hello" pipenv environment, create a file demo.py with the following content:

#%%
print("hello")

Clicking on "Run Cell" yields the error msg:
Running cells requires Jupyter notebooks to be installed.

Relevant excerpt from Pipfile.lock

        "jupyter-client": {
            "version": "==5.2.3"
        },
        "jupyter-console": {
            "version": "==6.0.0"
        },
        "jupyter-core": {
            "version": "==4.4.0"
        },

Logs

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

No output.

Output from Console under the Developer Tools panel (toggle Developer Tools on under Help)

/usr/share/code/resources/app/out/vs/workbench/workbench.main.js:294 [Extension Host] Python Extension: Error: Error executing Jupyter command 'nbconvert': [Errno 2] No such file or directory

t.log @ /usr/share/code/resources/app/out/vs/workbench/workbench.main.js:294
/usr/share/code/resources/app/out/vs/workbench/workbench.main.js:294 [Extension Host] Python Extension: Error: Running cells requires Jupyter notebooks to be installed.
t.log @ /usr/share/code/resources/app/out/vs/workbench/workbench.main.js:294
/usr/share/code/resources/app/out/vs/workbench/workbench.main.js:2429 Running cells requires Jupyter notebooks to be installed.

nbconvert is not available via the venv, but jupyter-nbconvert is.

Maybe Related

See https://github.com/Microsoft/vscode-python/issues/3341 and https://github.com/Microsoft/vscode-python/issues/3332

@sotte
Copy link
Author

sotte commented Nov 14, 2018

Update: It seem to be related to how you start vscode.

  • When vscode is started from the activated virtualenv code . then "run cell" works.
  • When vscode is started without any environment (and jupyter is not available in the current PATH)
    • "run cell" works with a conda interpreter
    • "run cell" does not work with the interpreter from the virtualenv

conda and virtualenv seem to be handled differently. Is this a bug or accepted behavior?

@rchiodo rchiodo self-assigned this Nov 15, 2018
@mrvkino
Copy link

mrvkino commented Nov 15, 2018

I have the same setup as @sotte except I am on MacOS Mojave 10.14.1. But, event if I start vscode within the environment started by Pipenv, vscode is not able to find Jupyter.

The Jupyter Python Package from @DonJayamanne is able to find the Jupyter executable.

@rchiodo
Copy link
Contributor

rchiodo commented Nov 16, 2018

I can't repro @sotte's bug on Linux, but I can on Windows. Hopefully the fix I have out will address the problem.

@sotte
Copy link
Author

sotte commented Nov 16, 2018

@rchiodo thanks for the quick reply!

I just checked 1.30.0-insider 24b0f75b1e33b88f30f2ed9d5b17ca60062c270b x64 and I have the same experience. It was a fresh insider install with no extensions other than the python one.

@rchiodo
Copy link
Contributor

rchiodo commented Nov 16, 2018

@sotte Ah, your venv doesn't support nbconvert so you can't do an import. There's a bug in the code that it checks for nbconvert instead of notebook being available.

This line here:
https://github.com/Microsoft/vscode-python/blob/40554c8effdba308744ff68de24e5fd83ee84f12/src/client/datascience/history.ts#L492

That line should say:
if (!(await this.jupyterExecution.isNotebookSupported())) {

Sorry took me so long to notice you didn't have nbconvert installed in your venv.

I'll submit a fix for this right away.

@rchiodo
Copy link
Contributor

rchiodo commented Nov 16, 2018

Should be fixed now in microsoft/vscode-python@d2a5e21

@rchiodo rchiodo closed this as completed Nov 16, 2018
@sotte
Copy link
Author

sotte commented Nov 17, 2018

@rchiodo thanks, you're great!

@leonjonathan
Copy link

@sotte Were you able to take advantage of the fix? I have very similar issue (macOS 10.14.1) and I've been navigating the related issues that've been merged, but can't make out if the fix is available

@sotte
Copy link
Author

sotte commented Dec 7, 2018

Yes, it worked for me. The fix is only available through the nightly/insider build though @leonjonathan

@leonjonathan
Copy link

Thanks @sotte, no luck for me though. Looks like the commit with the fix has already been pushed to Extension Version 2018.11.0, which is what I am using. After looking at #3774 it's worth mentioning that I'm on python 3.6.7 (pyenv install) and my virtual environment is created with venv (via pyenv-virtualenv), so maybe worth opening my own issue? @rchiodo

@rchiodo
Copy link
Contributor

rchiodo commented Dec 10, 2018

@leonjonathan if you're using a pip venv then #3774 is likely the culprit. If you start code from the terminal that has the environment activated, does it work then?

@leonjonathan
Copy link

leonjonathan commented Dec 10, 2018

@rchiodo Yes, works as expected when starting code with environment activated in terminal. Not using pipenv though (as in #3774). If I understand correctly, pipenv uses VirtualEnv, while pyenv-virtualenv uses native python3 -m venv despite its name

@lock lock bot locked as resolved and limited conversation to collaborators Jan 7, 2019
@microsoft microsoft unlocked this conversation Nov 14, 2020
@DonJayamanne DonJayamanne transferred this issue from microsoft/vscode-python Nov 14, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants