Vscode for python jupyter fail to show video - python-3.x

I'm trying to make a animation in the Jupyter of Visual Studio Code. The code is listed below.
import arviz as az
from IPython.display import HTML
from matplotlib.animation import FuncAnimation
import matplotlib.pyplot as plt
import numpy as np
import scipy.stats as st
...
...
...
anim = FuncAnimation(fig, update, frames=np.arange(bins.shape[0]),
init_func=init, blit=True, interval=20)
HTML(anim.to_html5_video())
However, the Jupyter fail to play the video on the Visual Studio Code. The result was shown in the picture below.

I'm also getting this issue. I've used this animation tutorial to confirm it was an VSCode issue and not my code, which I'd confirmed works in vanilla Jupyter.
I've installed JupyterLab for use with this code sample since it's easy enough to set up.
conda install -c conda-forge jupyterlab (or pip install jupyterlab)
jupyter lab
Executing the run command from the directory with your resources with default that as the run location of Jupyter so you shouldn't need to alter your code. Here's hoping they resolve this soon.

Related

How to reliably convince matplotlib to use PySide2 backend when running from Anaconda (Spyder)

I am creating a PySide2 application which uses matplotlib. I am running this application from Spyder in an environment with PySide2 installed. This is causing the application to be run from the iPython console. Somewhere along the line, PyQt5 is imported, which I am attempting to purge in order to convince matplotlib that I really do want to use PySide2, NOT PyQt5. Something like following was working until very recently and I am not really sure why it has stopped, but safe to say this method is unreliable. How can I absolutely convince matplotlib that I am wanting PySide2?
I have tried setting the environment variable QT_API in the operating system (Windows 10), but in this case Spyder itself refuses to open.
import sys
import os
ps = list(filter(lambda x: 'PyQt5' in x, sys.modules))
for p in ps:
print(f"purging module {p}")
sys.modules.pop(p)
# matplotlib.__init__ uses this
os.environ["MPLBACKEND"] = "PySide2"
# matplotlib.backends.qt_compat uses this
os.environ["QT_API"] = "PySide2"
import PySide2.QtCore
assert "PyQt5.QtCore" not in sys.modules
assert "PySide2.QtCore" in sys.modules
# rcParams has the right idea
from matplotlib import rcParams
print(rcParams["backend"])
# qt_compat has the WRONG idea!
import matplotlib.backends.qt_compat as qt_compat
print(qt_compat.QT_API)
# The FigureCanvasWidget is of the wrong (PyQt5) type
from matplotlib.backends.backend_qt5agg import FigureCanvas
import inspect
print(inspect.getmro(FigureCanvas))
To answer this question, the reason that it stopped working was because I had set 'activate support' for Matplotlib graphics in the ipython tab under Spyder settings. After unchecking this, the above works.

Installing opencv 3.4.2 with Anaconda

I'm running Ubuntu 18.04LTS:
Firstly, I couldn't install opencv from anaconda on my existing environment (base) as it kept searching for conflicts forever and then getting stuck with an empty window saying "these packages will be modified" while displaying absolutely nothing and with the only choice of pressing the "cancel" button.
I created a new virtual environment named env_opencv and was able to install opencv:
enter image description here
Then, I run a jupyter notebook that imports opencv:
import cv2
import matplotlib.pyplot as plt
import matplotlib.patches as patches
...
And here's what I get:
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-8-31cd2c78c525> in <module>
----> 1 import cv2
2 import matplotlib.pyplot as plt
3 import matplotlib.patches as patches
4
5 from align import AlignDlib
ModuleNotFoundError: No module named 'cv2'
No matter what I tried, including reinstalling opencv directly from the conda prompt, I can't get past this error.
Incidentally, I was able to make it work on Windows 10 going through the Anaconda prompt and using conda. However, my Windows machine doesn't have an nVidia GPU and I can't use it for CNN training, so I really need to make it work on Ubuntu.
Any suggestions would be great. Thank you.
I found a workaround to this issue:
I activate the env_opencv environment from the command line, then I launch jupyter notebook and it works.
Maybe, there is a bug with anaconda-navigator that doesn't seem to switch environments from the GUI?

Bqplot in jupyter lab returns a string instead of an (interactive) image

Today I've been trying to install the module bqplot and use jupyter lab for the very first time.
However, I've not been able to obtain the desired output when using the basic examples as shown on their website.
The code I'm trying to execute is as following:
import numpy as np
from bqplot import pyplot as plt
plt.figure(1, title='Line Chart')
np.random.seed(0)
n = 200
x = np.linspace(0.0, 10.0, n)
y = np.cumsum(np.random.randn(n))
plt.plot(x, y)
plt.show()
After running this code in a jupyter (lab) cell, the given output is:
VBox(children=(Figure(axes=[Axis(scale=LinearScale()), Axis(orientation='vertical', scale=LinearScale())], fig…
Whereas in the normal jupyter notebook, the output shows the example image.
I've so far no idea what has gone wrong and would appreciate any help!
Thanks.
I had the same issue and solved it by installing both the bqplot labextension and the #jupyter-widgets/jupyterlab-manager extension:
jupyter labextension install #jupyter-widgets/jupyterlab-manager
jupyter labextension install bqplot
After a restart of jupyter lab, the widgets are displayed.
I guess the misunderstanding lies in the installation instructions of bqplot: It only mentions these steps as "experimental JupyterLab extension", but the installation step for enabling bqplot in Jupter Lab misses them.

Not able to import pandas in jupyter notebook for Google cloud instance

I have done the setup of google cloud instance and also installed jupyter notebook. And I am able to start the jupyter notebook from my laptop. However when I run
import pandas as pd
It throws error. I tried to uninstall numpy and pandas and reinstall it from shell as well as from jupyter notebook. It does the new installation but again when I try to import pandas as pd, it still gives the same error.
What could be the error ? Is it something related to the path where it installs the library. How to debug this.

Conflict between tensorflow/PIL/pillow and scikit-image?

I am tying to rebuild my computer to run Spyder in a tensorflow environment for some image processing. In the past this worked and I had scikit-image working fully in that environment, and accessible from Spyder. Something has changed. I have:
1) re-installed Anaconda
2) re-installed tensorflow in a conda environment
3) installed libraries as needed, including Spyder.
Then I start Spyder from the Conda navigator, in the tensorflow environment. This seems to work, I can import tensorflow, keras, pandas, sklearn, etc. But skimage only works partially. for example:
import skimage
works fine. But,
import skimage.io as io
does not. The error comes out as 'from PIL import Image' Is this something about PIL/pillow not co-existing in the same environment? Can this be fixed easily or should I just use opencv for image io? I have tried other modules in skimage and they all import. So using another package to open an image would not be the end of the world, but it would be nice to get the entirety of skimage working.
Thanks

Resources