Questions tagged [ipython-magic]

A set of pre-defined "magic functions" of IPython that used with the command-line syntax.

A set of pre-defined "magic functions" of that used with the command-line syntax. There are two types of magic functions line-oriented and cell-oriented. The lines start with a magic % and executed from the command line. They get into an argument the rest of the line, where the arguments are passed without parentheses and quotation marks. Cell magic begins with the double %%, and they are functions that get in an argument not only the rest of the line, but the line below it in a separate argument.

169 questions
1
vote
0 answers

IPython magic-command %notebook does not work when spaces are present in path (Google Colab)

In jupyter-lab I can use the magic command %notebook $output_file_path to save the history notebook as a jupyter notebook. When I am working with Google Colab (mounting Google Drive) the path of my notebook folder is something like: root_path =…
1
vote
1 answer

How to stop an infinite loop safely in JupyterLab?

We are using jupyterLab for some long running operations (doing physic simulations in our case). The user should be able to stop these operations safely without killing the kernel. Is there a clean ways to do this? Are there maybe even best…
wotanii
  • 2,470
  • 20
  • 38
1
vote
0 answers

Continue execution of previous session log on exception

I'm trying to build a workflow for me to start and resume iPython sessions when debugging issues on a remote machine. I want to log everything I type in, replay it, and have execution continue on errors. With exception: I tried to access x before it…
Olshansky
  • 5,904
  • 8
  • 32
  • 47
1
vote
1 answer

ipython-sql: How to connect hive/presto with connect_args?

Note: I posted the question at https://github.com/catherinedevlin/ipython-sql/issues/149 I can connect hive/presto using create_engine like this from sqlalchemy.engine import create_engine conn = create_engine( 'presto://user@host:port', …
ZK Zhao
  • 19,885
  • 47
  • 132
  • 206
1
vote
1 answer

How to run iPython **line** magic from a script?

I've found a way to run magic commands, eg from IPython import get_ipython get_ipython().run_line_magic('matplotlib', 'inline') but how do you run something like !ls ? Specifically, I need this to run a console script at runtime in Google Colab.…
magicrebirth
  • 4,104
  • 2
  • 25
  • 22
1
vote
1 answer

magic function %hist not found Mac OSX

I'm using ipython on Mac OS X Snow leopard and for some reason I get an error when I use the hist magic function, even when giving it as %hist. When I give hist I get a python NameError and when I give %hist I get an ipython error ERROR: Magic…
Hassantm
  • 563
  • 1
  • 4
  • 14
1
vote
1 answer

Is there a way to run `%memit` inside a script without wrapping it in iphyton

I am logging the RAM usage of sagemath commands against each other and want to automate it I found %memit and I found information on wrapping each [command][How to run an IPython magic from a script (or timing a Python script) but that is not…
927589452
  • 13
  • 1
  • 5
1
vote
2 answers

Import .py flie into Jupyter Notebook line by line

I prefer to write my python code on VSCode because of its intellisense and autocomplete features. But I would rather see and debug the code on a Jupyter notebook to better visualize the data I am working with. I know I can load any file into Jupyter…
FTM
  • 1,887
  • 17
  • 34
1
vote
1 answer

Jupyter Lab/Notebook magic command %load with platform independent path

I am trying to develop a Jupyter notebook that includes cells that have the %load magic command to load code from elsewhere. This code is not in the same directory as where the notebook is. I want this to work on Windows, Linux and Mac, so path…
Marcel
  • 185
  • 1
  • 1
  • 7
1
vote
2 answers

Rmagic Anaconda Jupyter

I was trying to embed some r code on a python 2.7 kernel notebook but it doesn't work. I'm using Anaconda's Jupyter so i've tried : conda install rpy2 or conda install rpy2.ipython Unfortunately anytime I try to use %%R or %R nothing happens…
1
vote
1 answer

How to make caller's namespace available to IPython's magic inside imported function?

I'm trying to call a small helper-function defined in 'timex.py' which is called from 'caller.py', which in turn should get called from (PyCharm's) IPython-console through "%run caller.py". This currently results in "NameError: name 'pickle' is not…
Darkonaut
  • 20,186
  • 7
  • 54
  • 65
1
vote
0 answers

IPython autoreload doesn't work with Module level __init__.py

Let's assume we have the following package structure. module __init__.py +--> submodule __init__.py +--> subsubmodule __init__.py importantstuff.py Classes from importantstuff can be imported by writing from…
Joachim
  • 11
  • 2
1
vote
1 answer

Using the return values from one SQL statement in another SQL statement using SQL Magic in a Jupyter Notebook

I am working on a Jupyter Notebook on some standard DB2 table functions. I'd like to be able to refer to values returned from one SQL statement in other SQL statements. The syntax of the variable reference is getting me here. This is the code I use…
1
vote
1 answer

Using IPython's %%time magic within a script to measure CPU time

I work with Jupyter/IPython quite a lot and am used to including %%time magic command in front of each cell to get a hint of the amount of CPU and wall clock time spent. Is there a simple way to obtain the same measurements from within a…
KT.
  • 10,815
  • 4
  • 47
  • 71
1
vote
0 answers

run sub kernel in python kernel

I am trying to run the groovy kernel as a sub-kernel in python. I have added custom cell magic in python, so when user types %%groovy groovy kernel should be started using jupyter_client manager and execute code. currently, I am having a problem…
fishera
  • 789
  • 2
  • 7
  • 26