Whats an efficient workflow for my IPython projects?
Requirements:
easily open notebooks from anywhere
easily shift between many notebooks in different locations
support the rest of my workflow (ie. version control, manipulating project files outside of IPython
Motivation:
If you’re like me, you often work in IPython notebooks, continually open and close many different notebooks as you wind through your work day. Its often suggested to launch the IPYNBs from the command line with something like ipython notebook --pylab=inline but navigating back and forth between deeply nested dirs gets old fast. What’s the best way to get around this?
Use a .bat file!
An example of how to construct one for easy launching of IPython notebooks is shown below. Save the file as go.bat and then from the command line you can execute go “ipython_notebook’s name” to easily launch it from anywhere. (you can name it anything, go is just convenient.)
Because your working dir can now be easily pointed to your project dir: The project workflow conveniently supports some helpful operations from the command line.
Easy git commands -- push, pull, and version the crap out of the project
Easy project inspection – use start . to open your projects directory an easily manipulate files outside of IPython
Easy starting of an IPython cluster by adding pcluster start -n 4 to the start ipython notebook line in the batch file
Know of way to improve the workflow or a better way to do this? Let me know!
batch file:
#echo off
GOTO %1
:titanic
cd C:\Users\Andrew\Documents\Kaggle\Titanic\Dups\Kaggel-Titanic
start ipython notebook --pylab=inline
GOTO END
: NB
cd C:\Users\Andrew\Documents\IPython NoteBooks
start ipython notebook --pylab=inline
GOTO END
:END
Related
I have an Ansible workspace where I'm writing YML, PowerShell, and Python. Because of how things are set up where I work, I can't directly debug the YML files, so I need a custom launch configuration to run the files the way they are needed.
I'd love to just assign this to only YML extensions and leave the default debugger for Python and PowerShell files, as I switch between them quite often.
My current setup has a debug.ps1 file that will automatically switch between what it should launch based on the file that was debugged, but the Python files launch without the help of the Python debugger. I'd love for some way to either make that script launch the Python debugger, or make some sort of pre-debug task that tells VSCode what debugger to use.
Is there any way to do this?
Thanks!
I've used Git Bash for most bash-required tasks before, but since I've found WSL to be much more feature-rich as it's basically an entirely new subsystem. However, when I used to use VSCode along with Git Bash, it would simply cd into the working directory of the project for ease of use. However, it doesn't do that here. The only solutions I've found online are to create an entirely new Remote WSL VSCode window, but this is way too high maintenance for what I'm trying to do as I'm literally just trying to get VSCode to automatically cd into the correct directory. Thanks in advance.
Is it possible to write a python or bash script such that when I run it from the integrated terminal in vscode it closes the current window?
This may sound useless, so let me explain one use case in case you're wondering why I need to do this, and maybe you also have other suggestions to achieve it. I have a python script that allows me to easily rename a github repo name using github's api: something like rename-github-repo newname, which automatically detects the git project directory, makes the changes on github via the api, and renames the directory in my local filesystem as well. After the directory rename, my current vscode window is messed up because it references the old directory, so I'd like to close it and open a new one with the new directory as part of the script rename-github-repo so I don't have to do it manually.
I want to create a new jupyter file in any location of choice of my computer other than in the default folder. I am using windows 10. Just like any other applications, word, R etc, you have the choice to create and save it in anywhere but I could not figure out how to do that in jupyter.
When you are starting jupyter-notebook, first go to the desired directory where you want to create or save file and then start the notebook. Now, jupyter will run in that directory. You will be able to save your work (ex., ipynb files) in that directory.
I follow this whenever I work with jupyter notebook. I prefer this approach because in this way, you can start the jupyter-notebook in any desired directory.
You can see the official instruction to change the startup folder for jupyter-notebook in windows.
You can also do the following: using the jupyter notebook config file.
Open cmd and type jupyter notebook --generate-config
This writes a file to C:\Users\username.jupyter\jupyter_notebook_config
Change line 179. c.NotebookApp.notebook_dir = '' to c.NotebookApp.notebook_dir = 'your path'. [Make sure you use forward slashes in your path]
But you need to do this every time you want to start jupyter-notebook in a different directory. Thats why I don't prefer this approach (personal opinion).
You can this stackoverflow post too, in case if you get any help from it.
I am trying to add the hide_code option to my ipython notebook (jupyter, version 4, python 2.7). It is supposed to add a button or an option to the cell pull-down menu that allows me to hide the code in my ipython notebooks. I have successfully run the 'pip install hide_code' command from the terminal (MacOS X El Capitan). I have restarted the notebook and expected to see a new I have tried to restart the notebook program but nothing happens. I am not computer savvy enough to know what to do from here. Did I miss something?
Here is the github repository for the code:
https://pypi.python.org/pypi/hide_code/0.3.0
OK I found a way to do it.
Install hide_code... It will not work, though.
Try to install it with (with dir="~/.ipython" or whatever)
import hide_code.hide_code as hc;
dir = "<full path to Jupyter config directory>";
hc.install(dir)
It will still not work, but it will copy a javascript file (hide_code.js) into that directory. We will use it in a bit.
Let's find where those nbextensions are. Find one of them. For example, keyboard_shortcut_editor:
cd ~
find -name keyboard_shortcut_editor
Mine finds it ./.local/share/jupyter/nbextensions/keyboard_shortcut_editor
Yours should be there too.
Go to that directory
cd ./.local/share/jupyter/nbextensions/
ls
You see full list of various extensions. Let's copy one of them into hide_copy:
cp -r hide_input hide_code
cd hide_code
ls
The important file there is main.js. Replace it with that hide_code.js from ~./ipython
cp ~./ipython/hide_code.js ./main.js
Rename hide-input.yaml with hide-code.yaml and edit the content accordingly. Mainly, replace all Hide_Input references to Hide_Code. You can edit readme.md as well, but that doesn't matter. Because, the main thing, you created a new extension.
Now, if you launch your jupyter and go to http://localhost:8888/nbextensions, you will see Hide Code. And if click on that checkbox, it's on. Here are snapshots:
It is a weird sequence. But it worked for me. And the main thing, it puts it right where it needs to be. Hide_code actually needs to be a part of Nbextensions. I don't know why it is not. That way it's easy to turn it on and off any way you like it.
As described in the documentation: https://github.com/kirbs-/hide_code, you can troubleshoot by running the following code with appropriate Jupyter config directory location:
import hide_code.hide_code as hc
dir = "<full path to Jupyter config directory>"
hc.install(dir)