171 questions
0
votes
0
answers
118
views
How can I use %%scalene in Jupyter Notebook on GitHub Codespaces?
I'm trying to use the %%scalene cell magic in a Jupyter Notebook running on GitHub Codespaces to profile a Numba-accelerated implementation of the Mandelbrot set. However, when I run the following ...
0
votes
0
answers
74
views
Inadequate highlighting in code's output cells in an IPython notebook in VSCode
I am using VSCode to edit and run my IPython notebooks.
Upon using them, I wanted to preserve the coloring of some magic commands like !grep when I used them. Thanks to this question here on SE, I ...
2
votes
2
answers
210
views
Error running a magic programmatically via IPython's run_cell_magic
Consider the following program, which I wrote in two Jupyter Notebook cells.
Cell 1:
import rumbledb as rmbl
%load_ext rumbledb
%env RUMBLEDB_SERVER=http://public.rumbledb.org:9090/jsoniq
Cell 2:
%%...
2
votes
1
answer
2k
views
How do I use Jupyter/IPython magic commands in VSCode?
I saw someone else using magic commands in VSCode, but when I try them, I get a syntax error. How do I get them to work?
File "tmp.py", line 1
%cd
^
SyntaxError: invalid syntax
...
0
votes
1
answer
2k
views
Graph not showing when add in %matplotlib notebook using Jupyter in VS Code
When using Jupyter on VS Code, when I add in %matplotlib notebook, the graph would not show at all
When I start to plot without the magic everything is working fine.
When graph is not showing after ...
0
votes
1
answer
108
views
Using CONCAT in column alias
I have a bunch of repeating queries in a Python accessed SQL notebook. I've tested the below
colum_to_agg = f'''data_col_1'''
sql_aggregates_query=f'''
avg({colum_to_agg}) as (concat({colum_to_agg},'...
1
vote
0
answers
340
views
Create a custom magic in a Glue Studio Notebook
I've been trying to create custom magic for a Glue Studio Notebook, like the following example (taken from here)
I've adding the Ipython module by running the glue magic
%additional_python_modules ...
2
votes
1
answer
3k
views
How to run an IPython CELL magic from a script (%% magic)
Jupyter magic commands (starting with a single %, e.g. %timeit) can be run in a script using the answer from How to run an IPython magic from a script (or timing a Python script)
However, I cannot ...
2
votes
1
answer
1k
views
iPython custom cell magic - store output in variable?
I recently discovered iPython magic functions and wrote some custom magic. I would like to use cell magic to parse strings, change them slightly and return the result.
Is there a way to store the ...
0
votes
0
answers
135
views
%debug magic command not working in the Q# Jupyter Notebook environment
As per the documentation provided by Microsoft Azure Quantum at this link , I followed the steps given and installed Q# with Jupyter Notebook, using Anaconda.
I then wrote the following Q# program in ...
3
votes
2
answers
1k
views
Jupyter %%prun magic output not displayed properly in VS Code
Since very recently I have a problem where the output of %%prun is not displayed properly in VS Code Jupyter (all output is on one line instead of in a nicely formatted table).
I tried reloading the ...
1
vote
1
answer
525
views
Stop the effect of %matplotlib notebook in Jupyter notebook
I used the magic commands %matplotlib notebook at some ceil in my notebook to animate some scatter plots.
However, after that ceil, I want to remove the effect of this magic command.
Anyone has any ...
1
vote
1
answer
162
views
A way to use the declared C++ function in Ipython with cpp magic?
In Ipython can someone use a FORTRAN function in python code,with this way:
%load_ext fortranmagic
%%fortran
subroutine f1(x, z)
real, intent(in) :: x
real, intent(out) :: z
integer :: i
...
0
votes
1
answer
1k
views
Why does `IPython.display.Javascript(...)` work to run a Javascript command in a Jupyter cell but not in an IPython magic?
I'm trying to write a Jupyter nbextension where the user can configure the notebook-wide extension behavior using IPython magics. I'm planning on siting the configuration data on the JS side, under an ...
1
vote
0
answers
197
views
Define a IPython magic which replace and "update" the content of the next cell
Let's say I have [cell 1] following notebook (I know that could also import this ipython-magic from ~/.ipython/profile_default/startup/:
[cell 1]
from IPython.display import display, HTML, ...
1
vote
0
answers
69
views
Is there a way to get only custom registered magics list but not all magic links ( %lsmagic ) in Jupyter notebook / python?
There is magic link "%lsmagic" to list all available magic links, I want to list only custom registered magic links.
Is there any way to list only custom magic links?
0
votes
1
answer
147
views
How to use `client.start_ipython_workers()` in dask-distributed?
I am trying to get workers to output some information from their ipython kernel and execute various commands in the ipython session. I tried the examples in the documentation and the ipyparallel ...
0
votes
0
answers
105
views
Using %%timeit results in permission error for large datasets
I'm reading a 1.5 GB CSV file and performing group by operation using jupyter notebook. It works fine when I run the following -
path = r"C:\Users\Downloads\Answers.csv"
df = pd.read_csv(...
6
votes
1
answer
927
views
Define a IPython magic which replaces the content of the next cell
The %load line-magic command loads the content of a given file into the current cell, for instance, executing:
[cell 1] %load hello_world.py
... transform the cell into:
[cell 1] # %load ...
0
votes
1
answer
360
views
%timeit is working individually but failing with .py file
I am trying to capture majic (%timeit) command results to text file, same executing individually in ipython but calling in .py file, it's throwing syntax error. please help me what exactly missing in ...
1
vote
0
answers
301
views
IPython Scrolling Issue With magic('clear') | Spyder
When running the code below on Spyder, part of the code shown on the IPython console disappears (i.e. it auto scrolls too far down)
get_ipython().magic('clear')
for i in range(10): print(i)
But it ...
0
votes
0
answers
2k
views
Store or read stored variable in jupyter notebooks, using try/except
I am using the %store magic to save a variable, then I'd like to %store -r that variable in the same notebook, different execution.
In order to automate this, I'd like to do something like:
try:
%...
0
votes
1
answer
639
views
Programmatically check for and disable IPython autoreload extension
I have a function that uses the Python importlib package to dynamically reload modules which generates some errors when the user is running the code from IPython and has the autoreload extension ...
1
vote
1
answer
565
views
IPython shortcut for importing pytest fixtures
Suppose that I am writing a test called test_this_thing in IPython which I intend to progressively save into a test file test_some_tests.py.
When it comes to running my tests I can do that easily from ...
1
vote
0
answers
142
views
Ipython - persistent variables between sessions
I would like to be able to use python in a way that I can save a session with the data, load it up and carry on with the variables that were in memory. Some of the variables can be fairly large (~1GB),...
1
vote
1
answer
3k
views
How to give alias name to commands in jupyter notebook?
I want to give an alias to a command in jupyter notebook such that if i write:
Get me list of all students
this alias name will call a command that I have written and show the desired result
Please ...
-1
votes
1
answer
2k
views
Import functions that use ipython magic
In ipython cells you can execute shell commands as follows:
ipython:
print("asdf")
!echo asdf
However, if you try to import this code from file,
asdf.py:
def asdf():
print("asdf"...
-1
votes
1
answer
241
views
Packaging a Python project and its associated IPython magic extension
I am in the process of deploying to Pypi a Python project, let's call it foobar. I would like to distribute it with a shell command and an IPython magic command. I use Poetry, and the relevant part of ...
2
votes
1
answer
120
views
IPython: Print string results
I want to make IPython automatically print all str results.
In [13]: 'hi\nhi' # I don't want this output
Out[13]: 'hi\nhi'
In [14]: print(_) # I want it like this, but without using print on every ...
0
votes
1
answer
1k
views
lost ipython history - database locked
Was playing with ipython history commands, experimenting with combining -l and -g to search a limited amount of history, and using -n to see which session a command came from.
Suddenly I got an ...
0
votes
1
answer
1k
views
Can I define magic_arguments for my ipython magic without using the decorator approach?
I have defined a custom iPython magic like this:
%%writefile pymagic.py
from IPython.core import magic_arguments
@magic_arguments.magic_arguments()
@magic_arguments.argument('--include', '-i', ...
2
votes
0
answers
787
views
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 ...
3
votes
1
answer
1k
views
Add reStructuredText support for Juptyer notebooks
I needed to view reStructuredText files in JupyterLab, and the best I found so far was @akaihola's answer to a related issue on github.
I added a work around that would allow rendering the file ...
1
vote
1
answer
4k
views
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 ...
1
vote
0
answers
132
views
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 ...
11
votes
1
answer
4k
views
Difference between % and %% in ipython magic commands
What difference does it make to use %timeit and %%timeit in ipython? Because when I read the documentation using ?%timeit and ?%%timeit it was the same documentation. So, what difference does adding % ...
1
vote
1
answer
989
views
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 = ...
1
vote
1
answer
2k
views
How to run iPython **line** magic from a script? [duplicate]
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 ...
1
vote
1
answer
2k
views
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 (...
2
votes
1
answer
756
views
IPython magic extension not found
I want to look at a database schema using %load_ext schemadisplay_magic then %schema but schemadisplay_magic will load. I get an error message saying:
No module named 'schemadisplay_magic'
IPython ...
2
votes
1
answer
11k
views
How to auto-reload code loaded by load magic in Jupyter notebook?
Jupyter Notebook has a %load magic that can load code into a cell of a notebook.
%load start.py
This line loads the content of start.py into the current cell. The magic is automatically commented out ...
5
votes
3
answers
4k
views
Connecting to SQL Server via SQL magics in Jupyter Lab
I am trying to connect to our remote sql server db via Jupyter Labs using the SQL magics. I can connect with a traditional connection string, but the SQL magics doesnt seem to work (which means I am ...
0
votes
1
answer
2k
views
How to get interactive R output in Jupyter (IPython, rpy2), e.g. for a progress bar?
I am trying to use the built-in R progress-bar (txtProgressBar) with %%R magic in Jupyter. While it does produce a nice animation when executed in the R console or RStudio, it does not produce the ...
10
votes
2
answers
1k
views
How to put a comment after a IPython magic command
How can I put a comment at the end of an IPython magic command?
Eg, trying to use %cd:
%cd "dir" # comment
I want to change to directory dir but instead I get:
[Errno 2] No such file or ...
1
vote
2
answers
2k
views
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 ...
2
votes
1
answer
2k
views
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 ...
3
votes
1
answer
2k
views
%lprun could not get result in jupyternotebook
Code:
def combCreate(grp,num):
d = chain(*(map(lambda x: (combinations(x,num)),grp)))
return set(d)
# Comb DataFrame abt Freq & occured date
def combFrame(grp):
arr = df.loc[:,'date':...
9
votes
1
answer
3k
views
%%time Does not return CPU time on Windows in Jupyter notebook
I am using %%time in Jupyter-notebook to measure run time of my Python code. The problem is that it prints only the Wall time on Windows but works fine on Ubuntu.
Is it possible to get the CPU time ...
1
vote
2
answers
285
views
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 ...
2
votes
0
answers
550
views
'%matplotlib notebook' behavior in Jupyter Lab [duplicate]
Currently Jupyter Labs does not support Java Script,
which causes the ipython magic '%matplotlib inline' to fail with the error: 'JavaScript output is disabled in JupyterLab'
I was wondering if ...