Jupyter windows shortcut corrupt by default

▼魔方 西西 提交于 2019-12-12 07:47:00

问题


After installing Anaconda, the Jupyter notebook shortcut works fine. Other stackoverflow answers have indicated that you can change the default working directory by changing the "Start In:" field in the shortcut properties. However, if Anaconda is installed in the suggested folder for single users C:\Users\whshg0\AppData\Local\Continuum\Anaconda3\, then the Target field of the shortcut gets truncated when you edit the Start in field. Example:

C:\Users\user01\AppData\Local\Continuum\Anaconda3\python.exe C:\Users\user01\AppData\Local\Continuum\Anaconda3\cwp.py C:\Users\user01\AppData\Local\Continuum\Anaconda3 "C:/Users/user01/AppData/Local/Continuum/Anaconda3/python.exe" "C:/Users/user01/AppData/Loc

al/Continuum/Anaconda3/Scripts/jupyter-notebook-script.py" gets truncated. After you click ok, Jupyter Notebook will no longer open.

What is a fast way to rebuild the Jupyter Notebook shortcut so the Target is not limited to the 255 character limit?


回答1:


The cleanest way I found to change the default working directory is to edit the cwp.py file in the Anaconda folder as following (at the end of the file):

Replace this line:

os.chdir(documents_folder)

with the folder you want to start in:

os.chdir("C:\\Private_Files\\MachineLearning")




回答2:


I was able to remake the shortcut by pointing the shortcut to:

C:\Users\user01\AppData\Local\Continuum\Anaconda3\Scripts\jupyter-notebook.exe

I lost the icon but I'm sure with some searching I can find it again.




回答3:


In Environment variables create System variable Anaconda3 (or other name) with the value:

C:/Users/user01/AppData/Local/Continuum/Anaconda3

Then substitute first 3 entries of:

C:/Users/user01/AppData/Local/Continuum/Anaconda3

in Shortcut -> Target with %Anaconda3%. This will make the target line length < 255.




回答4:


I installed miniconda instead of Anaconda because i was tired of anaconda crashing while updating. So anaconda prompt and jupyter notebook shortcuts had to be built manually.

For Anaconda Prompt, the shortcut:

  • Target: C:\Windows\System32\cmd.exe "/K" "%Localappdata%\Continuum\miniconda3\Scripts\activate.bat"
  • Start in: my preferred start location, eg C:\users\me\Onedrive\Projects

For Jupyter notebook, the shortcut:

  • Target: %localappdata%\Continuum\miniconda3\python.exe %LocalAppData%\Continuum\miniconda3\cwp.py %LocalAppData%\Continuum\miniconda3 "%LocalAppData%\Continuum\miniconda3\python.exe" "%LocalAppData%\Continuum\miniconda3\Scripts\jupyter-notebook-script.py"
  • Start in: didn't matter (see below)

(Replace miniconda3 with Anaconda3). Pointing to jupyter-notebook.exe as people suggested above did not work unless I was an activated environment, which I was not with a desktop shortcut.

Unfortunately setting the Start In field did not open jupyter in that folder, so maybe step 2 is @Bellaiche's suggestion. I followed the instructions here to set the Jupyter startup folder: How to change the Jupyter start-up folder.

Added the shortcuts to %appdata%\Microsoft\Windows\Start Menu\Programs\Anaconda3 just to have them on the start menu.




回答5:


FYI I found another issue with the shortcut on Windows 7. The Target string of the Jupyter Notebook start menu item had a %HOME% argument at the end. (a) There is no %HOME%, but there is a%HOMEPATH%, so change it to that if you want to start in your home directory. (b) An alternative way to specify the start up directory is to use the Start In field in the Properties dialog box (http://jupyter-notebook-beginner-guide.readthedocs.io/en/latest/execute.html). To do it the latter way, remove the final path argument from Target.




回答6:


I have tried to shorten path by defining my own %anaconda3% variable but my prompt opens and closes within 1 second if i ever edit the target or start in fields. of shortcut properties.

According to https://medium.com/@joelclay/access-your-jupyter-notebook-running-on-windows-10-from-any-computer-427bb06309ce the contents of target are C:\Users\joel\Anaconda3\python.exe C:\Users\joel\Anaconda3\cwp.py C:\Users\joel\Anaconda3 “C:/Users/joel/Anaconda3/python.exe” “C:/Users/joel/Anaconda3/Scripts/jupyter-notebook-script.py” I am careful to leave space between the lines and see that last 2 of them are strings with reversed slashes.

Finally my hack was to create a .bat file containing %anaconda3%\scripts\activate.bat & jupyter notebook and put this bat file in my jupyter shortcut target so it does the same thing as opening Anaconda Prompt and typing jupyter notebook




回答7:


The problem was resolved. The shortcut was the issue.

I had to manually change the "Shortcut target" to the following:

C:\Users\'yourusername'\AppData\Local\Continuum\Anaconda3\Scripts\jupyter-notebook.exe




回答8:


Change c.NotebookApp.notebook_dir = '' to desired directory.

It will work from Anaconda prompt, but will not with a shortcut. Originally shortcut is too big, that big, that it gets truncated. Actually with jupyter running we don't need cwp.py because the paths assigned there are useless in our case. Change the target of a shortcut to:

C:\Users\USER\AppData\Local\Continuum\Anaconda3\python.exe "C:/Users/USER/AppData/Local/Continuum/Anaconda3/Scripts/jupyter-notebook-script.py"

Change USER to user on your computer, don't forget to change backslash to forward slash in an argument.



来源:https://stackoverflow.com/questions/36994414/jupyter-windows-shortcut-corrupt-by-default

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