My motivation here is to develop new functions that should live in external modules, and I'd like to use a jupyter notebook for interactive development.
Is there a way to set a breakpoint or similar in an external .py file that will let me export the current namespace right back to the jupyter notebook, so code in another cell can run within the scope of the breakpoint?
I've tried using pdb etc. but I want something more along the lines of code.interact(), but that lets me then use the full features of a jupyter notebook.
Related
In my Pycharm projects I use Jupyter to experiment and when something is mature enough I move it to Python files within the project, and make the notebook use it.
From time to time, while running a notebook I change that Python code but am forced to manually restart the server in order to make the notebook use the changed code.
I'd like Pycharm to automatically do it for me.
Is there a way?
I'm testing codes from Colab, where you can just show the result without using print function, such as:
df.Quantity.dtypes
but in PyCharm, you have to run as the following to show the result:
print(df.Quantity.dtypes)
It's really time consuming if such commands are frequent.
How could I print out without using print functin in PyCharm just as Colab?
Thanks a lot!
You would have to create a Jupyter notebook, but note that this is a Professional feature, which means this won't work in PyCharm Community Edition.
Here's how to do it:
Create a new Python project, specify a virtual environment, and install the jupyter package.
Open or create an .ipynb file.
Add and edit source cells.
Execute any of the code cells to launch the Jupyter server.
More on PyCharms Jupyter features can be found here.
As an alternative, you could you the Python Console. Take a look at this question to learn more.
My Jupyter/IPython notebooks reside in various directories all over my file system. I don't enjoy navigating hierarchies of directories in the Jupyter notebook browser every time I have to open a notebook. In absence of the (still) missing feature allowing to bookmark directories within Jupyter, I want to explore if I can open a notebook from the command line such that it is opened by the Jupyter instance that is already running. I don't know how to do this....
Option 1: Run multiple jupyter notebook servers from your project directory root(s). This avoids navigating deeply nested structures using the browser ui. I often run many notebook servers simultaneously without issue.
$ cd path/to/project/; jupyter notebook;
Option 2: If you know the path you could use webbrowser module
$ python -m webbrowser http://localhost:port/path/to/notebook/notebook-name.ipynb
Of course you could alias frequently accessed notebooks to something nice as well.
I have a custom Jupyter kernel which runs IPython using a custom IPython profile which uses a matplotlib stylesheet.
I know to run this successfully normally I would put:
The matplotlib stylesheet in ~/.config/matplotlib/stylelib/
The IPython profile in ~/.ipython/
The kernel json in ~/.jupyter/kernels/my_kernel/
But I am doing this as part of larger program which runs in a virtualenv, and if I put the things as above then any notebook server running on the computer will be able to see the custom kernels, even if it is running outside the venv. I don't what this because I don't want my program to interfere with other notebooks on the computer.
I think what I need to do is put the things above somewhere equivalent inside the venv but I can't figure out where they should go. Doe anyone know where they would go? Or is this just a thing IPython/Jupiter can't/won't do?
It's probably worth mentioning that in the case of the stylesheet for example I don't want to just put it in the working directory of my program (which is one option matplotlib offers).
You can put kernelspecs in VIRTUAL_ENV/share/jupyter/kernels/ and they will be made available if the notebook server is running in that env. In general, <sys.prefix>/share/jupyter/kernels is included in the path to look for kernelspecs.
You can see the various locations Jupyter will look, you can see the output of jupyter --paths:
$ jupyter --paths
config:
/Users/you/.jupyter
/Users/you/env/etc/jupyter
/usr/local/etc/jupyter
/etc/jupyter
data:
/Users/you/Library/Jupyter
/Users/you/env/share/jupyter
/usr/local/share/jupyter
/usr/share/jupyter
runtime:
/Users/you/Library/Jupyter/runtime
Kernelspecs are considered data files, and will be found in any of those directories listed under data:, in a kernels subdirectory, e.g. /usr/local/share/jupyter/kernels.
I'm using spyder and pycharm for python coding. When I plot something with matplotlib in spyder it shows the result inline in IPython.
With Pycharm IPython plots in a new extra window.
I'm working on Windows7 and with Anaconda Python2.7.
Is it possible to plot in Pycharm inside in the IPython shell?
Not inside the shell; however, you can use an iPython notebook within PyCharm (2016+) for that purpose. PyCharm supports iPython plots when defined within a .ipynb (iPython/Jupyter file format) script.
Here is an example:
Open, or create (as shown) a .ipynb script:
An here is what you get if you code inside a freshly made .ipynb file within PyCharm 2016 or later. Notice the %matplotlib inline, which comes after matplotlib.pyplot import.
PyCharm 2019.1+
In this version of PyCharm several great features to integrate Jupyter Notebooks and PyCharm were added.
First, create a new Jupyter Notebook or open up an existing one.
Second, you can Insert a new cell or you can work on existing cells.
Third, you can Run or Debug a Cell:
Fourth, if you run the cell, the result will be reflected in the right side of the screen.