无法正确安装和使用pythreejs

时间:2020-01-07 19:06:00

标签: installation jupyter pythreejs

我按照official website

上的说明安装了pythreejs
pip3 install pythreejs
jupyter nbextension install --user --py pythreejs
jupyter nbextension enable --user --py pythreejs

看看jupyter nbextension list的输出,一切看起来都很好:

Known nbextensions:
  config dir: /home/gael/.jupyter/nbconfig
    notebook section
      jupyter-threejs/extension  enabled 
      - Validating: OK

但是,当我启动服务器(jupyter notebook)时,创建一个新的(Python3)笔记本,并尝试运行示例代码

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)

来自pythreejs的official repository,它没有向我显示页面中嵌入的可视化窗口。而是在单元格下方显示一个哈希:

UmVuZGVyZXIoY2FtZXJhPVBlcnNwZWN0aXZlQ2FtZXJhKGNoaWxkcmVuPShEaXJlY3Rpb25hbExpZ2h0KGNvbG9yPSd3aGl0ZScsIGludGVuc2l0eT0wLjUsIHBvc2l0aW9uPSgzLjAsIDUuMCzigKY=

我还尝试了使用jupyter实验室和Python2,它的行为完全相同。

我想念什么?

系统:Ubuntu 18.04 Jupyter Notebook版本:5.7.8

1 个答案:

答案 0 :(得分:0)

更仔细地查看控制台中jupyter的输出,我读到:

[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

我遵循advice for this error

jupyter nbextension enable --py widgtesextension

然后启动服务器:pythreejs可以正常工作!