Using a .bat to change directories and run Jupyter

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Using a .bat to change directories and run Jupyter



I'm new to coding but I simply want to change directory and run jupyter. The problem is cmd instantly closes once it reaches the jupyter notebook command. Tried cmd /k too but it doesn't have an effect. I must being doing this wrong.


F:
cd directoryname
activate environmentname
jupyter notebook
pause



Solution:
The commands were closing the prompt for some reason when executed in a .bat (they don't when typed). The fix was to type call before the commands.


F:
cd directoryname
call activate environmentname
call jupyter notebook
pause




5 Answers
5



Assuming activate and jupyter are executables or otherwise valid commands, everything should be okay. Since you're saying the cd command is probably the culprit, try the below:


activate


jupyter


cd



Perhaps you are trying to change to a directory on a different drive... if this is the case you will need to use cd /d directoryname instead.


cd /d directoryname



If this doesn't work, try putting a bunch of pause statements between each command to see exactly where it is breaking.


pause





Pauses between and after all commands results in cmd instantly closing after activate environmentname runs (it skips the post command pause) However either cmd /k activate environment or cmd /k jupyter notebook properly runs either command. But I cannot run both commands using this method.
– Jubei
Feb 21 '16 at 22:05



activate environmentname


cmd /k activate environment


cmd /k jupyter notebook



The commands were closing the prompt for some reason when executed in a .bat (they don't when typed). The fix was to type call before the commands.


F:
cd directoryname
call activate environmentname
call jupyter notebook
pause



Create a simple batch file (jnote.bat):


@echo off
call jupyter notebook "%CD%"
pause



In the same folder create a shortcut to the batch file and rename it to jupyter-notebook.



Open the shortcut properties and change the icon to the jupyter.ico. You will find this in the .Menu sub-folder in your Anaconda distribution. You should now have a shortcut with the) nice jupyter icon.



Copy the shortcut to all the folders that you use for your notebooks.
Double-click the shortcut to open jupyter-notebook that folder.



For Windows,


C:Users**UserName**Anaconda3python.exe C:Users**UserName**Anaconda3cwp.py C:Users**UserName**Anaconda3 C:Users**UserName**Anaconda3python.exe C:Users**UserName**Anaconda3Scriptsjupyter-notebook-script.py "**file location**"



Save it in a .bat file, with necessary changes at 'UserName' and 'File Location' . Keep it As a single line
And just need to double click on the file to open jupyter notebook at the location.
Note: File Location is the location of the notebook to open.



I found an alternative way to solve this problem without a .bat.



Search your start menu for "Jupyter Notebook". You should find a shortcut called:



"Jupyter Notebook (environmentname)"



This short cut was created when I set up my environment. In my case environmentname is py35.



To change the directory that Jupyter Notebook starts in find the "Anaconda Prompt" shortcut. Then open "Properties>Shortcut" and change the "Starts in:" field to your desired directory.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS