Jupyter commands work only with a dash (e.g. jupyter-kernelspec instead of jupyter kernelspec)

一世执手 提交于 2019-12-10 12:58:51

问题


I am using Jupyter with Anaconda3.

My Anaconda3\ and Anaconda3\Scripts\ folders have been added to the %PATH% variable.

Eventhough the jupyter.exe is in the Scripts folder above, Jupyter related commands don't work without a dash.

  • For example:

    jupyter kernelspec --version
    Error executing Jupyter command 'kernelspec': [Errno 'jupyter-kernelspec' not found] 2
    
  • The same command with a dash works:

    jupyter-kernelspec --version
    5.2.2
    

And the same goes for jupyter-notebook, etc.

Do I have to add anything else to my %PATH%? Am I missing something?

I have opened an issue for this point on Github as well, but it didn't get any attention unfortunately: https://github.com/jupyter/jupyter/issues/381


回答1:


Well, I figured out what's wrong. Using the shutil module, in some Windows versions which('jupyter-kernelspec') returns None, because of the missing .exe, although the PATHEXT environment variable contains both .exe and .EXE.

(This seems to be linked to this: shutil.which() not finding programs without appending file extension although I am not convinced because which(jupyter-kernelespec.EXE) using shutil works fine for me...)

So, one has to add the .exe to the argument of jupyter like this:

jupyter kernelspec.exe list

Because this kind of command is used by most Jupyter kernel installers, you won't always be able to go debug and check where you need to add it. The fix consists in adding this:

if cmd[-4:] != '.exe':
    cmd = cmd + '.exe'

right before this line: https://github.com/jupyter/jupyter_core/blob/f1e18b8a52cd526c0cd1402b6041778dd60f20dc/jupyter_core/command.py#L102

I'll try to raise this point with shutil module people.

I've updated also the github issue and closed it. https://github.com/jupyter/jupyter/issues/381



来源:https://stackoverflow.com/questions/50484397/jupyter-commands-work-only-with-a-dash-e-g-jupyter-kernelspec-instead-of-jupyt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!