Context: I'm using vscode with WSL and I also use conda for environment management.
I'm trying to create a variable in a jupyter notebook, let's say x = [10, 20], and then use that same variable in a .py file (not on jupyter notebooks). I'm already using the same environment on both, but the terminal/kernel I believe is different for each. I believe this because when I run a cell on jupyter notebook, nothing happens on the terminal. However, when I run on .py files, the terminal runs the code I selected.
I would like to see the terminal running something for jupyter (.ipynb) and also for my .py files.
Any help would be really appreciated.
Is it possible to run the Jupyter Notebook environment without creating a new .ipynb file? I often find myself in need of quick data inspection and feel like creating a new notebook would not be necessary but the perks of the notebook environment would be very appreciated because some operations might turn out to be quite bothersome using only the Python terminal interpreter.
I have a project containing a bunch of Python modules (.py files) and a bunch of Jupyter Notebooks (.ipynb files) which import things from the Python modules.
I can (assuming I've got __init__.py files in all subfolders) type-check all the .py files by simply running mypy . from the root of the project. But I'd like to also be able to type-check my Jupyter Notebooks.
An ideal solution would:
type check all Python code in my Jupyter Notebooks,
be able to follow imports of .py modules from within Jupyter Notebooks when type-checking, just like imports in .py files,
let me type-check the whole project from the command line, so that I can run type-checking as part of a test suite or a pre-commit hook, and
in some way meaningfully report the locations of type errors within my Notebooks, analogously to how mypy prints line numbers for errors in .py files.
How can I do this?
You could use nbQA and do
pip install -U nbqa
nbqa mypy your_notebook.ipynb
You can:
Convert all notebooks to python, then run mypy on that (How do I convert a IPython Notebook into a Python file via commandline?).
jupyter nbconvert --to script [YOUR_NOTEBOOK].ipynb
Just write a small script to do this and you are fine :)
Checkout nb-mypy
Nb Mypy is a facility to automatically run mypy on Jupyter notebook cells as they are executed, whilst retaining information about the execution history.
More details here
I use Jupytext and my IDE for this.
I export a copy in py:percent format, link that to the notebook. I Do the development in the jupyter lab environment, but the .py file is the one that goes in the git repository. Before commiting, I run it throught the usual linters, black, pydocstyle, mypy (with a strict configuration). I then reload the notebook in Jupyter lab, restart the kernel and 'Run All' to make sure the results are still OK, and only then commit the file to the repository
I have a jupyter notebook with both html and python code in it. Is it possible to write a script that will launch the notebook and run it in the browser? Most solutions on the web refer to running these scripts from the command line, but I want them to show up on the
I'm not sure what OS you're on, but here's a small batch file that moves into my directory with my .ipynb files, starts Jupyter, and then opens a specific notebook of mine:
cd "%userprofile%\desktop\att"
start chrome.exe http://localhost:8888/notebooks/ATT_SQL.ipynb#
jupyter notebook
I just put this on my desktop and double click it to start Jupyter. Just replace your notebook's name where mine is ATT_SQL.ipynb#. You'll also have to change the cd command as well.
Edit:
Or better yet:
cd %userprofile%\path\to\your\jupyter\dir
jupyter notebook yourNotebook.ipynb
Source
I am scratching my head on what the standard workflow is for opening, editing and executing a scripts directly from within the ipython notebook? I know that you can use %edit from ipython terminal but this doesn't seem to work from notebook.
thank you
in ipython 1.1.0 I just ran "!gvim a.py" in the notebook which opened the gvim editor in a window. After saving the edits into a.py file, I was able to successfully execute "%run a.py"