How do I unload an iPython extension that doesn't define how to unload itself? - ipython

I've loaded the autoreload iPython extension using:
In [1]: %load_ext autoreload
I want to unload it, but the following results:
In [1]: %unload_ext autoreload
The autoreload extension doesn't define how to unload it.
So, who can help me out here?

Related

How to resolve Pylance "import could not be resolved" in VSCode Jupyter Notebook?

I am trying to import function query_creative inside of file query_creative.py into the notebook Notebook.ipynb. The file hierarchy is like this:
├───playground
│ Notebook.ipynb
├───src
├───queries
query_creative.py
The code I use in my notebook goes like this:
import sys
sys.path.append('..')
from src.query.query_creative import query_creative
and the thing works. However, the line with the function import is underlined by Pylance with the message: "Import could not be resolved" and when I use this function later on, it works but Pylance underlines it again. I've tried modifying the setting.json, but nothing seems to work. I thank in advance for any help!
I managed to solve it eventually by downgrading Jupyter extension to VS Code to v2022.4.1001071005. Thanks everyone for help!
Which version of vs code you have? I faced with same issue after updating to 1.70.
UPD.
Downgrading to 1.69.2 fixed that issue. However, I have another laptop with 1.70 with exact same notebook there is no such issue, so if you want to stick around 1.70 it is worth to try to completely remove vscode and install it again.
UPD2.
After a while my downgrade didn't help on another machine, so I compared Pylance output difference between them and find out, that "working" instance used legacy jupyter notebook support, while "buggy" with "LSP". After disabling option Pylance Lsp Notebooks Enabled everything worked as usual and fixed that problem
It seems that pylance is unable to determine that the code is importable. Instead of modifying your path at the beginning of the script, you could create a Python package with your code, then do:
cd your-project
pip install -e .
You can see a guide to create packages here.
With these settings, pylance and any other editor/IDE will be able to identify your project correctly.
Beware that in VSCode, you can switch the interpreter, so ensure you select one where your code is installed:
https://blog.csdn.net/qq_41019681/article/details/111193080
"python.analysis.extraPaths": [
"D:\\ProgramFiles\\Anaconda3-2021.05\\lib\\site-packages"
]
add "python.analysis.extraPaths" by
import package_name as pkg
print(pkg.__file__)

Can't launch PySpark in browser (windows 10)

I'm trying to launch PySpark notebook in my browser by typing in pyspark from the console, but I get the following error:
c:\Spark\bin>pyspark
python: can't open file 'notebook': [Errno 2] No such file or directory
What am I doing wrong here?
Please help?
Sounds like the jupyter notebook is either not installed or not in your path.
I prefer to use Anaconda for my python distribution and Jupyter comes standard and will install all necessary path information as well.
After that as long as you have set PYSPARK_PYTHON_DRIVER=jupyter and PYSPARK_PYTHON_DRIVER_OPTS='notebook' correctly you are good to go.
You want to launch the jupyter notebook when you invoke the command pyspark. Therefore you need to add the following to the bash_profile or zshrc_profile.
export PYSPARK_SUBMIT_ARGS="pyspark-shell"
export PYSPARK_DRIVER_PYTHON=ipython
export PYSPARK_DRIVER_PYTHON_OPTS="notebook" pyspark

how to add autoreload to ptipython?

In ipython, we could use the following code to enable auto reload feature.
%load_ext autoreload
%autoreload 2
Now I am using ptipython, I could just type them every time using ptipython, but is there anything that could be automatically executed? such as .bashrc for bash shell.
There is a config.py which will be automatically run. But
%load_ext autoreload
is not python code, so looks like I can't put them here. Any other solutions to avoid type them manually?

How to include iPython notebook

I would like to import functions from one iPython's notebook into another iPython's notebook. Is it possible? If so how to achieve it?
Try this: import iPython functions.
Helped me as well.

Display of music21, musicXML PNG objects using iPython Notebook/Enthought Canopy

I am experimenting with the music21 library, in preparation for a Machine Learning project that involves genre classification and categorization. I and following some tutorials available here. I am using MuseScore as my MusicXML program, and I am trying to run the whole thing from iPython.
Although I can run the some of the turtorials from the terminal, some elements don't seem to run well from inside iPython. For example:
In [3]: sBach.show()
Out[3]: <music21.ipython21.objects.IPythonPNGObject at 0x10da0aa10>
The line above shows that the PNG object is created, but not displayed. The expected output for 3 above is the following:
Experimenting with the following iPython command, I get a placeholder for an image, but not image.
In [6]: %load_ext music21.ipython21.ipExtension
In [7]: sBach.show()
I can't find any problem with my MusicXMLPath. This tutorial refers to the use of musc21 with Anaconda, but all my developments is done with Enthought, so I prefer not to run another virtual environment to use music21 with iPython.
Is there any way to run music21 in an Enthought/iPython notebook?
I have been grappling with this issue myself. ... Have you set your musicxmlPath in music21? If you have not, it's done via environment.set(key, value). You can query for available keys with environment.keys(). I hope this isn't too simple an answer, but it cleared up the problem for me.
This should be in the iPython music21 documentation somewhere, my apologies: iPython in music21 requires Lilypond to be installed for images to be generated within the notebook itself. There hasn't been (and won't be until MuseScore 2.0 is released) a way using MusicXML to generate PNG images of scores directly.
Edit: 2015 July; music21 2.0 w/ MuseScore 2 will generate the PNG images with MuseScore if it is installed and fallback to Lilypond if it is not installed.
If not yet tried, some steps to isolate the cause of the problem:
1) Update to the latest Canopy (Edit: currently 1.4.1) (might help this, will help generally, won't hurt).
2) Change the Pylab backend in Canopy's IPython shell to "Inline (SVG)", via Preferences / Python. (The default Qt backend in that shell conflicts with music21's use of the tkinter library.)
3) Test your script in that shell rather than in the notebook.
4) Ensure that Canopy User Python is your default Python in a Terminal window, as described here.
5) Test your scripts inside of plain ipython terminal (from Terminal, type ipython).
6) Test in ipython terminal in pylab mode (ipython qtconsole --pylab=inline).
7) Test your scripts inside of ipython notebook running in a regular browser (from Terminal, type ipython notebook, and/or ipython notebook --pylab=inline).
Had similar issues before. It's the same problem when people try to use plot function in ipython/jupyter notebook. You need to call
%matplotlib inline
For me the issue was solved by uninstalling the snap version of musescore and installing it from ppa:mscore-ubuntu/mscore3-stable via https://launchpad.net/~mscore-ubuntu/+archive/ubuntu/mscore3-stable