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

Python Launcher does not work for Python terminal or Python Interactive window #3619

Closed
bcoov opened this issue Feb 6, 2019 · 13 comments
Closed
Assignees

Comments

@bcoov
Copy link

bcoov commented Feb 6, 2019

Environment data

  • VS Code version: 1.31.0
  • Extension version (available under the Extensions sidebar): 2019.1.0
  • OS and version: Windows 7 Enterprise SP1, 64-bit
  • Python version (& distribution if applicable, e.g. Anaconda): Python 3.7.2 32-bit & Python 2.7.14 64-bit
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): N/A
  • Relevant/affected Python packages and their versions: (Python 3) jupyter-notebook 5.7.4; (Python 2) jupyter-notebook 5.2.2

Expected behaviour

Clicking "Run-Cell" above a note-book enabled snippet starts and runs Jupyter Notebook

Actual behaviour

Clicking "Run-Cell" triggers an error stating "Executing code failed : Error: Running cells requires Jupyter notebooks to be installed."

Running py -m notebook from a cmd window and/or VSCode's terminal starts jupyter notebook as expected for Python 3 and similarly py -2 -m notebook for Python 2.

Steps to reproduce:

  1. Have at least Python 3 (for the launcher) installed using default options (Python Launcher on PATH, Python Executable not on PATH) and with jupyter-notebook module installed. Have no other versions of Python on PATH, only the launcher (C:\Windows\py.exe)
  2. Select Python 3.x as interpreter.
  3. Create a simple notebook snippet and try to run the cells
#%%
msg = "Hello World"
print(msg)

Logs

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

Starting Jedi Python language engine.

Output from Console under the Developer Tools panel (toggle Developer Tools on under Help; turn on source maps to make any tracebacks be useful by running Enable source map support for extension debugging)

console.ts:134 [Extension Host] Python Extension: Cached data exists ActivatedEnvironmentVariables, <No Resource>

console.ts:134 [Extension Host] Python Extension: Cached data exists getEnvironmentVariables, <No Resource>

console.ts:134 [Extension Host] Python Extension: getActivatedEnvironmentVariables, Class name = S, Arg 1: undefined, Arg 2: {"architecture":2,"path":"C:\\Python37-32\\python.exe","version":{"raw":"3.7.2-final","major":3,"minor":7,"patch":2,"prerelease":["final"],"build":[],"version":"3.7.2-final"},"sysPrefix":"C:\\Python37-32","fileHash":"d84cbeced9380942287d24afb8ff1ca2b1eb881dd92e80f1e21a101cdf2c4f2aa28a2629baad07c6dbd1528b0bc445f6d2a52c9cd30baf402a76b89c82ecdd0b","companyDisplayName":"Python Software Foundation","type":"Unknown","displayName":"Python 3.7.2 32-bit"}

console.ts:134 [Extension Host] Python Extension: Cached data exists getEnvironmentVariables, <No Resource>

console.ts:134 [Extension Host] Python Extension: Activation Commands received undefined

console.ts:134 [Extension Host] Python Extension: getActivatedEnvironmentVariables, Class name = S, Arg 1: undefined, Arg 2: {"architecture":3,"path":"C:\\Python27\\python.exe","version":{"raw":"2.7.14-final","major":2,"minor":7,"patch":14,"prerelease":["final"],"build":[],"version":"2.7.14-final"},"sysPrefix":"C:\\Python27","fileHash":"45320b6ecc01ba85d63e7b3a68c02dfe545da607d62447b640dab7cdc589e0b7f087fd3a5b48c27eb06c6b9a9bda6a2326bf1e62e8b4c2d83f1ea190ec714a12","companyDisplayName":"Python Software Foundation","type":"Unknown","displayName":"Python 2.7.14 64-bit"}

console.ts:134 [Extension Host] Python Extension: Cached data exists getEnvironmentVariables, <No Resource>

console.ts:134 [Extension Host] Python Extension: Error: Error executing Jupyter command 'notebook': [Errno 'jupyter-notebook' not found] 2
 for C:\Python27\python.exe
t.log @ console.ts:134
e.$logExtensionHostMessage @ mainThreadConsole.ts:39
t._doInvokeHandler @ rpcProtocol.ts:390
t._invokeHandler @ rpcProtocol.ts:375
t._receiveRequest @ rpcProtocol.ts:295
t._receiveOneMessage @ rpcProtocol.ts:225
(anonymous) @ rpcProtocol.ts:100
e.fire @ event.ts:567
s @ ipc.net.ts:295
(anonymous) @ ipc.net.ts:302
e.fire @ event.ts:567
a @ ipc.net.ts:103
_socketDataListener @ ipc.net.ts:132
emit @ events.js:182
addChunk @ _stream_readable.js:279
readableAddChunk @ _stream_readable.js:264
Readable.push @ _stream_readable.js:219
onread @ net.js:636

console.ts:134 [Extension Host] Python Extension: Error: Error executing Jupyter command 'notebook': [Errno 'jupyter-notebook' not found] 2
 for C:\Python37-32\python.exe
t.log @ console.ts:134
e.$logExtensionHostMessage @ mainThreadConsole.ts:39
t._doInvokeHandler @ rpcProtocol.ts:390
t._invokeHandler @ rpcProtocol.ts:375
t._receiveRequest @ rpcProtocol.ts:295
t._receiveOneMessage @ rpcProtocol.ts:225
(anonymous) @ rpcProtocol.ts:100
e.fire @ event.ts:567
s @ ipc.net.ts:295
(anonymous) @ ipc.net.ts:302
e.fire @ event.ts:567
a @ ipc.net.ts:103
_socketDataListener @ ipc.net.ts:132
emit @ events.js:182
addChunk @ _stream_readable.js:279
readableAddChunk @ _stream_readable.js:264
Readable.push @ _stream_readable.js:219
onread @ net.js:636

console.ts:134 [Extension Host] Python Extension: Error: spawn jupyter ENOENT
t.log @ console.ts:134
e.$logExtensionHostMessage @ mainThreadConsole.ts:39
t._doInvokeHandler @ rpcProtocol.ts:390
t._invokeHandler @ rpcProtocol.ts:375
t._receiveRequest @ rpcProtocol.ts:295
t._receiveOneMessage @ rpcProtocol.ts:225
(anonymous) @ rpcProtocol.ts:100
e.fire @ event.ts:567
s @ ipc.net.ts:295
(anonymous) @ ipc.net.ts:302
e.fire @ event.ts:567
a @ ipc.net.ts:103
_socketDataListener @ ipc.net.ts:132
emit @ events.js:182
addChunk @ _stream_readable.js:279
readableAddChunk @ _stream_readable.js:264
Readable.push @ _stream_readable.js:219
onread @ net.js:636

notificationsAlerts.ts:40 Executing code failed : Error: Running cells requires Jupyter notebooks to be installed.
@bcoov bcoov changed the title Launching Jupyter Notebook does not work with Python launcher Launching Jupyter Notebook does not work with Python Launcher Feb 6, 2019
@rchiodo
Copy link
Contributor

rchiodo commented Feb 7, 2019

Not sure we support py as the python executable. This would be an extension wide problem, @DonJayamanne ?

@rchiodo
Copy link
Contributor

rchiodo commented Feb 7, 2019

@bcoov , I assume running python -m notebook --version fails from the vscode terminal?

@bcoov
Copy link
Author

bcoov commented Feb 11, 2019

@rchiodo that is correct, it just returns 'python' is not recognized as an internal or external command, operable program or batch file (since python.exe isn't on my PATH)

@rchiodo
Copy link
Contributor

rchiodo commented Feb 12, 2019

@d3r3kk I don't think this is datascience specific. The python terminal doesn't work either.

@rchiodo rchiodo changed the title Launching Jupyter Notebook does not work with Python Launcher Python Launcher does not work for Python terminal or Python Interactive window Feb 13, 2019
@brettcannon
Copy link
Member

@bcoov what do you have "python.pythonPath" set to? It should be set to an actual Python interpreter and not py.

@bcoov
Copy link
Author

bcoov commented Feb 15, 2019

@brettcannon My vscode pythonPath is "python.pythonPath": "C:\\Python37-32\\python.exe".

If it helps, I can change interpreters between 3.7 and 2.7 using the Ctrl + Shift + P menu as expected (py launcher does not show in this list), and > Python: Start REPL opens the terminal into the appropriate Python interpreter.

@brettcannon brettcannon removed their assignment Feb 21, 2019
@brettcannon
Copy link
Member

OK, so it seems the py aspect of the issue was a red herring; @bcoov was just saying he can launch jupyter from the command-line on Windows. Kicking it back to you, @rchiodo 😁

@bcoov are you sure the that the Python interpreter you have for py that can run jupyter matches the one you are selecting in the Python extension? Just double-checking as I know I have made the mistake of using py and not realizing I accidentally installed into a different environment/interpreter.

@bcoov
Copy link
Author

bcoov commented Feb 21, 2019

@brettcannon jupyter is installed for both interpreters, so I'm positive that it's using the correct one 🙂 Python 3.7 is the default interpreter to py though, so if I want to run jupyter under Python 2.7, I would have to run py -2 -m notebook.

@IanMatthewHuff
Copy link
Member

@bcoov. Sorry about the delay on this. I'm on the data science team and I've now picked this up to investigate. From what I can tell we can do a little bit of work here to make this easier for you, but there is also a reasonable workaround for you to try.

I set up the same scenario as you and I can repro the issue. However I can only repro this issue when the python scripts directory is not active on the PATH variable. If the scripts path is added to the path then the Interactive Windows works. Also if you are working with either an activated virtualenv or with an activated conda env then the script path will be added and this works as expected. Doing any of those things would be the best way to get this working for you.

More Info:
Currently we run our jupyter commands using the following format.
python.exe (or py.exe) -m jupyter notebook --version

This format only works if the scripts directory is on the path. When the scripts directory is not on the path most of the commands will work with the following format:
python.exe -m notebook --version

I'm going to change our code to fallback to the non-jupyter version if the jupyter version fails. I think this should unblock the basic scenario. However some of the commands (like the jupyter kernelspec command) still don't work in this situation. So even after this fix I would recommend creating a virtual env or conda env for your project (so that it can be activated) or adding your python scripts directory to the path.

@bcoov
Copy link
Author

bcoov commented Mar 20, 2019

Thanks for the update @IanMatthewHuff! I added the Scripts directory to my PATH to try the workaround you suggested. After restarting VSCode and trying to run the cell, it sat there reporting "Starting Jupyter Server" indefinitely. However, after another restart, running the cell again started up the server instance and ran as expected.

@IanMatthewHuff
Copy link
Member

Sounds good. My fix to run this without the scripts directory has been merged in, so it will ship with our next extension update. Should be in about a week from now.

@bcoov
Copy link
Author

bcoov commented Apr 5, 2019

@IanMatthewHuff Apologies for the delay. Finally got a chance to test out the 2019.3.6139 merged fix - everything looks good on my end! 😄

@IanMatthewHuff
Copy link
Member

Thanks for reporting that back @bcoov. Glad to know that you are unblocked now.

@lock lock bot locked as resolved and limited conversation to collaborators May 8, 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

5 participants