Can't install and use properly pythreejs - installation

I installed pythreejs following the instructions on the official website
pip3 install pythreejs
jupyter nbextension install --user --py pythreejs
jupyter nbextension enable --user --py pythreejs
Looking at the output of jupyter nbextension list, everything looks fine:
Known nbextensions:
config dir: /home/gael/.jupyter/nbconfig
notebook section
jupyter-threejs/extension enabled
- Validating: OK
But when I start the server (jupyter notebook), create a new (Python3) notebook, and try to run the example code
from pythreejs import *
import numpy as np
from IPython.display import display
from ipywidgets import HTML, Text, Output, VBox
from traitlets import link, dlink
ball = Mesh(geometry=SphereGeometry(radius=1, widthSegments=32, heightSegments=24),
material=MeshLambertMaterial(color='red'),
position=[2, 1, 0])
c = PerspectiveCamera(position=[0, 5, 5], up=[0, 1, 0],
children=[DirectionalLight(color='white', position=[3, 5, 1], intensity=0.5)])
scene = Scene(children=[ball, c, AmbientLight(color='#777777')])
renderer = Renderer(camera=c,
scene=scene,
controls=[OrbitControls(controlling=c)])
display(renderer)
from pythreejs' official repository, it does not show me a visualization window embedded in the page. Instead, below the cell it displays a hash:
UmVuZGVyZXIoY2FtZXJhPVBlcnNwZWN0aXZlQ2FtZXJhKGNoaWxkcmVuPShEaXJlY3Rpb25hbExpZ2h0KGNvbG9yPSd3aGl0ZScsIGludGVuc2l0eT0wLjUsIHBvc2l0aW9uPSgzLjAsIDUuMCzigKY=
I also tried with jupyter lab, and with Python2, and it had exactly the same behavior.
What am I missing?
System: Ubuntu 18.04
Jupyter Notebook version: 5.7.8

Looking more closely at jupyter's output in the console, I read:
[W 18:55:45.544 NotebookApp] 404 GET /nbextensions/widgets/notebook/js/extension.js?v=20200107185531 (127.0.0.1) 14.69ms referer=http://localhost:8889/notebooks/Untitled.ipynb?kernel_name=python3
Following advice for this error I do:
jupyter nbextension enable --py widgtesextension
then start the server: and pythreejs works!!

Related

floWeaver does not draw basic diagrams from quick tutorial and does not show error message

Following the floWeaver tutorial and beginning with the Quickstart where flows are defined, the second step of plotting the flows does not work. The problem is that I do not get any error message.
The code consists of two blocks, with the second block not working..
import pandas as pd
flows = pd.read_csv('simple_fruit_sales.csv')
from ipysankeywidget import SankeyWidget
SankeyWidget(links=flows.to_dict('records'))
https://sankeyview.readthedocs.io/en/latest/tutorials/quickstart.html
Python version installed: 3.6.10
floWeaver version: 2.0.0
Many thanks in advance!
Just make sure that you have the following installation, other than the package itself.
pip install ipysankeywidget
jupyter nbextension enable --py --sys-prefix ipysankeywidget
jupyter nbextension enable --py --sys-prefix widgetsnbextension

Jupyter lab build fail after installing plotly extension

Plotly figures are not rendered/displayed in jupyterlab. I therefore tried to install the extension jupyter labextension install #jupyter-widgets/jupyterlab-manager jupyterlab-plotly. Afterwards I was asked to run the jupyter lab build and this failed. I have no idea where the problem is.
Install info:
I installed a venv with pyenv running python 3.8.5.
jupyter --version
jupyter core : 4.7.1
jupyter-notebook : 6.4.0
qtconsole : not installed
ipython : 7.25.0
ipykernel : 6.0.3
jupyter client : 6.1.12
jupyter lab : 3.0.12
nbconvert : 6.1.0
ipywidgets : 7.6.3
nbformat : 5.1.3
traitlets : 5.0.5
npm --version
7.11.2
node --version
v16.1.0
I am restricted to use WSL1 because of company requirements.
I’ll post below the command outputs for
jupyter labextension list
jupyter lab build
cat /tmp/jupyterlab-debug-5vr2zquq.log
jupyter labextension install #jupyter-widgets/jupyterlab-manager --minimize=False
Any advice would be appreciated. I have no idea how to fix this.
Thanks
❯ jupyter labextension list
JupyterLab v3.0.16
/home/bebop/.local/share/jupyter/labextensions
#jupyter-widgets/jupyterlab-manager v3.0.0 enabled OK (python, jupyterlab_widgets)
/mnt/s/dokumente/Privat/neue_fische/ot/ot-sopra_steria/.venv/share/jupyter/labextensions
jupyterlab-plotly v5.1.0 enabled OK
Other labextensions (built into JupyterLab)
app dir: /mnt/s/dokumente/Privat/neue_fische/ot/ot-sopra_steria/.venv/share/jupyter/lab
plotlywidget v4.14.3 enabled OK
Build recommended, please run jupyter lab build:
plotlywidget needs to be included in build
❯ jupyter lab build
[LabBuildApp] JupyterLab 3.0.16
[LabBuildApp] Building in /mnt/s/dokumente/Privat/path/.venv/share/jupyter/lab
[LabBuildApp] Building jupyterlab assets (production, minimized)
Build failed.
Troubleshooting: If the build failed due to an out-of-memory error, you
may be able to fix it by disabling the dev_build and/or minimize options.
If you are building via the jupyter lab build command, you can disable
these options like so:
jupyter lab build --dev-build=False --minimize=False
You can also disable these options for all JupyterLab builds by adding these
lines to a Jupyter config file named jupyter_config.py:
c.LabBuildApp.minimize = False
c.LabBuildApp.dev_build = False
If you don’t already have a jupyter_config.py file, you can create one by
adding a blank file of that name to any of the Jupyter config directories.
The config directories can be listed by running:
jupyter --paths
Explanation:
dev-build: This option controls whether a dev or a more streamlined
production build is used. This option will default to False (i.e., the
production build) for most users. However, if you have any labextensions
installed from local files, this option will instead default to True.
Explicitly setting dev-build to False will ensure that the production
build is used in all circumstances.
minimize: This option controls whether your JS bundle is minified
during the Webpack build, which helps to improve JupyterLab’s overall
performance. However, the minifier plugin used by Webpack is very memory
intensive, so turning it off may help the build finish successfully in
low-memory environments.
An error occured.
shutil.Error: [(’/mnt/s/dokumente/Privat/path/.venv/lib/python3.8/site-packages/jupyterlab/staging/templates’, ‘/mnt/s/dokumente/Privat/path/.venv/share/jupyter/lab/staging/templates’, “[Errno 13] Permission denied: ‘/mnt/s/dokumente/Privat/path/.venv/share/jupyter/lab/staging/templates’”)]
See the log file for details: /tmp/jupyterlab-debug-5vr2zquq.log
❯ cat /tmp/jupyterlab-debug-5vr2zquq.log
[LabBuildApp] Building in /mnt/s/dokumente/Privat/path/.venv/share/jupyter/lab
[LabBuildApp] Node v16.1.0
[LabBuildApp] Yarn configuration loaded.
[LabBuildApp] Building jupyterlab assets (production, minimized)
[LabBuildApp] Traceback (most recent call last):
[LabBuildApp] File “/mnt/s/dokumente/Privat/path/.venv/lib/python3.8/site-packages/jupyterlab/debuglog.py”, line 47, in debug_logging
yield
[LabBuildApp] File “/mnt/s/dokumente/Privat/path/.venv/lib/python3.8/site-packages/jupyterlab/labapp.py”, line 166, in start
raise e
[LabBuildApp] File “/mnt/s/dokumente/Privat/path/.venv/lib/python3.8/site-packages/jupyterlab/labapp.py”, line 162, in start
build(name=self.name, version=self.version,
[LabBuildApp] File “/mnt/s/dokumente/Privat/path/.venv/lib/python3.8/site-packages/jupyterlab/commands.py”, line 469, in build
return handler.build(name=name, version=version, static_url=static_url,
[LabBuildApp] File “/mnt/s/dokumente/Privat/path/.venv/lib/python3.8/site-packages/jupyterlab/commands.py”, line 657, in build
self._populate_staging(
[LabBuildApp] File “/mnt/s/dokumente/Privat/path/.venv/lib/python3.8/site-packages/jupyterlab/commands.py”, line 1180, in _populate_staging
shutil.copytree(pjoin(HERE, ‘staging’, ‘templates’), templates)
[LabBuildApp] File “/home/bebop/.pyenv/versions/3.8.5/lib/python3.8/shutil.py”, line 554, in copytree
return _copytree(entries=entries, src=src, dst=dst, symlinks=symlinks,
[LabBuildApp] File “/home/bebop/.pyenv/versions/3.8.5/lib/python3.8/shutil.py”, line 510, in _copytree
raise Error(errors)
[LabBuildApp] shutil.Error: [(’/mnt/s/dokumente/Privat/path/.venv/lib/python3.8/site-packages/jupyterlab/staging/templates’, ‘/mnt/s/dokumente/Privatpath/.venv/share/jupyter/lab/staging/templates’, “[Errno 13] Permission denied: ‘/mnt/s/dokumente/Privat/path/.venv/share/jupyter/lab/staging/templates’”)]
[LabBuildApp] Exiting application: JupyterLab
❯ jupyter labextension install #jupyter-widgets/jupyterlab-manager --minimize=False
Building jupyterlab assets (production, not minimized)
An error occured.
shutil.Error: [(’/mnt/s/dokumente/Privat/path/.venv/lib/python3.8/site-packages/jupyterlab/staging/templates’, ‘/mnt/s/dokumente/path/.venv/share/jupyter/lab/staging/templates’, “[Errno 13] Permission denied: ‘/mnt/s/dokumente/Privat/path/.venv/share/jupyter/lab/staging/templates’”)]
You should not need to install the extension from source. JupyterLab 3.0 introduced prebuilt extensions system that allows users to install extensions from pip (and conda) without the need for the build step making all the trouble of troubleshooting failed builds disappear. It seems that you used an old set of instructions for installing plotly, as plotly 5.0+ supports prebuilt extensions for JupyterLab. First uninstall the source extensions that you just installed (non of those are needed):
jupyter labextension uninstall #jupyter-widgets/jupyterlab-manager jupyterlab-plotly plotlywidget
Optional: verify list of extensions with:
jupyter labextension list
Then install a new plotly version with pip or conda:
pip install "plotly>=5" "ipywidgets>=7.6"
# or, if using conda:
# conda install -c conda "plotly>=5"
# conda install "ipywidgets>=7.6"
Both widget and renderer are included, so no need to install plotlywidget separately.
Check list of extensions again:
jupyter labextension list
You should now see lines with:
jupyterlab-plotly v5.1.0 enabled OK
#jupyter-widgets/jupyterlab-manager v3.0.0 enabled OK (python, jupyterlab_widgets)
(the version may be newer in the future of course).

opencv issues with M1 MAC - OpenCV imshow doesnot work

I purchased a M1 Mac. Is anyone having issues with imshow with opencv. I did pip install opencv-python and brew install opencv and brew install opencv as well.
import cv2
import urllib
import numpy as np
import requests
url = 'https://www.visitcalifornia.com/sites/visitcalifornia.com/files/styles/welcome_image/public/vc_crtr_borntobewild_module_mendocino_st_rf_623667652_1280x640.jpg'
from skimage import io
img = io.imread(url)
img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
cv2.imshow('URL Image', img)
cv2.waitKey()
and also
import cv2
cv2.namedWindow("preview")
vc = cv2.VideoCapture(0)
if vc.isOpened(): # try to get the first frame
rval, frame = vc.read()
else:
rval = False
while rval:
cv2.imshow("preview", frame)
rval, frame = vc.read()
key = cv2.waitKey(20)
if key == 27: # exit on ESC
break
cv2.destroyWindow("preview")
vc.release()
does not work for me
It was solved by
pip install opencv-python opencv-python-headless
I was able to solve this by building from the source code of OpenCV 4.5, use this link to get the source code
Try to install Miniconda from https://docs.conda.io/en/latest/miniconda.html
then activate it and try to install cv2 pip install opencv-python
getting 80-90 FPS for just reading image & showing
from my side, all are working in M1 using Miniconda
Opening the terminal in rosetta and doing a pip install(inside virtual environment) helped me build the opencv. Before this , while I was doing it with the M1 terminal, it was giving errors stating some architecture issue. Guess this did the trick to me.
Create Virtual Environment -> Activate it -> (Rosetta Terminal) -> pip3 install opencv-python
Install OpenCV using pip. This normally gives a ffmpeg error, so install that first
First do:
pip3 install ffmpeg
and then
pip3 install opencv-python
I thought I had the same issue. The window was not popping up when using cv2.imshow() or cv2.namedWindow(). I realized hours later that the window was there in the Mac menu bar, I just had to click on it.

Biopython for Anaconda on OSX "No module named 'Bio'" error

When I import Bio in a Jupyter notebook in Anaconda on a Mac I this error: No module named 'Bio'.
Somehow the import settings weirdly case sensitive. This will fix it:
# Installing the biopython libraries in this runtime environment
!pip3 install biopython==1.78
# The next two lines fix the error "No module named 'Bio'"
# that occurs with an Anaconda Navigator installation on OSX
# by making python imports case insensitive
import os
os.environ['PYTHONCASEOK'] = '1'
# On to regularly scheduled imports.
import Bio
Further experiments show that other permutations won't work in both google colab and Jupyter; and I am not sure why:
I have run some experiments with this and after uninstalling all bio and biopython variants (just to be sure, they were not actually installed), I fount that
!pip3 install bio
import bio
works on anaconda but not on google colab. If I import Bio with a capital B it works on neither of them.
!pip3 install bio
import os
os.environ['PYTHONCASEOK'] = '1'
import Bio
print("All's well")
works on Jupyter but errors out "ModuleNotFoundError: No module named 'Bio'" on collab. Import lower case bio behaves the same.
# Solution that works on both colab.google.com and
# Anaconda Navigator Jupyter notebooks
!pip3 install biopython
import os
os.environ['PYTHONCASEOK'] = '1'
import Bio
works for Anaconda Jupyter and Google Colab. If you change the case to 'import bio' it stops working on Google.

PyCharm: Using SIFT with opencv-contrib (Mac)

I have a Python/OpenCV project and I am trying to use the xfeatures2d module from opencv-contrib. I am using a Mac and my IDE is PyCharm. I have installed the packages opencv-contrib-python and opencv-python through Preferences > Project Intepreter.
However, when I try to run the code below, I get a the following error:
import cv2
import numpy as np
img = cv2.imread("NotreDame.jpg", 0)
sift = cv2.xfeatures2d.SIFT_create()
line 6, in <module>
sift = cv2.xfeatures2d.SIFT_create()
cv2.error: OpenCV(4.1.0) /Users/travis/build/skvark/opencv-python/opencv_contrib/modules/xfeatures2d/src/sift.cpp:1207: error: (-213:The function/feature is not implemented) This algorithm is patented and is excluded in this configuration; Set OPENCV_ENABLE_NONFREE CMake option and rebuild the library in function 'create'
I have installed opencv and opencv-contrib on my computer using:
$ pip install opencv-python==3.4.2.17
$ pip install opencv-contrib-python==3.4.2.17
I am not sure how I can resolve this error. Any insights are appreciated.

Resources