简体   繁体   English

nglview 已安装但不会通过 Anaconda.Navigator 导入到 Juypter Notebook 中

[英]nglview installed but will not import inside Juypter Notebook via Anaconda.Navigator

I'm having trouble importing nglview inside a Juypter Notebook (JNb) cell.我在 Juypter Notebook (JNb) 单元格中导入 nglview 时遇到问题。 The instance of JNb is started via the base (root) Environment inside Anaconda.Navigator GUI. JNb 的实例是通过 Anaconda.Navigator GUI 中的基础(根)环境启动的。 Inside Anaconda.Navigator, I've installed nglview.在 Anaconda.Navigator 中,我安装了 nglview。 But the import continues to fail.但是导入仍然失败。

Versions:版本:

  • Jupyter Notebook (inside Anaconda.Navigator) - 6.4.12 Jupyter Notebook(在 Anaconda.Navigator 内)- 6.4.12
  • Anaconda.Navigator (GUI) - 2.3.2 Anaconda.Navigator (GUI) - 2.3.2
  • Python - 3.9 Python - 3.9
  • nglview - 3.0.3 (installed but not importing) nglview - 3.0.3(已安装但未导入)
  • ipython 8.5.0 ipython 8.5.0

This is the error:这是错误:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In [1], line 5
      3 import pandas as pd
      4 import matplotlib.pyplot as plt
----> 5 import nglview as nv
      7 # the next line is necessary to display plots in Jupyter
      8 get_ipython().run_line_magic('matplotlib', 'inline')

File ~\anaconda3\lib\site-packages\nglview\__init__.py:4
      1 import warnings
      3 # for doc
----> 4 from . import adaptor, datafiles, show, widget
      5 from ._version import get_versions
      6 from .adaptor import *

File ~\anaconda3\lib\site-packages\nglview\show.py:13
      3 from . import datafiles
      4 from .adaptor import (ASEStructure, ASETrajectory, BiopythonStructure,
      5                       FileStructure, HTMDTrajectory, IODataStructure,
      6                       IOTBXStructure, MDAnalysisTrajectory, MDTrajTrajectory,
   (...)
     11                       RdkitStructure,
     12                       TextStructure)
---> 13 from .widget import NGLWidget
     15 __all__ = [
     16     'demo',
     17     'show_pdbid',
   (...)
     40     'show_biopython',
     41 ]
     44 def show_pdbid(pdbid, **kwargs):

File ~\anaconda3\lib\site-packages\nglview\widget.py:19
     15 from traitlets import (Bool, CaselessStrEnum, Dict, Instance, Int, Integer,
     16                        List, Unicode, observe, validate)
     17 import traitlets
---> 19 from . import color, interpolate
     20 from .adaptor import Structure, Trajectory
     21 from .component import ComponentViewer

File ~\anaconda3\lib\site-packages\nglview\color.py:114
    110         else:
    111             raise ValueError(f"{obj} must be either list of list or string")
--> 114 ColormakerRegistry = _ColormakerRegistry()

File ~\anaconda3\lib\site-packages\nglview\base.py:10, in _singleton.<locals>.getinstance()
      8 def getinstance():
      9     if cls not in instances:
---> 10         instances[cls] = cls()
     11     return instances[cls]

File ~\anaconda3\lib\site-packages\nglview\color.py:47, in _ColormakerRegistry.__init__(self, *args, **kwargs)
     45 try:
     46     get_ipython() # only display in notebook
---> 47     self._ipython_display_()
     48 except NameError:
     49     pass

File ~\anaconda3\lib\site-packages\nglview\color.py:54, in _ColormakerRegistry._ipython_display_(self, **kwargs)
     52 if self._ready:
     53     return
---> 54 super()._ipython_display_(**kwargs)

AttributeError: 'super' object has no attribute '_ipython_display_'

What is missing?什么东西少了? I need to resolve this issue within the GUI of Anaconda.Navigator, as I need nglview as part of an exercise for students who do not have a background in computational sciences.我需要在 Anaconda.Navigator 的 GUI 中解决这个问题,因为我需要 nglview 作为没有计算科学背景的学生练习的一部分。 I'm not after a solution that uses anything but the GUI.我不追求使用 GUI 以外的任何东西的解决方案。 Asking a group over Zoom to start hacking around with a Mac/Windows/Linux terminal would be a nightmare.通过 Zoom 要求一组人开始使用 Mac/Windows/Linux 终端进行黑客攻击将是一场噩梦。 Many thanks.非常感谢。

UPDATE Recent efforts have included:更新最近的努力包括:

  • closing and restarting Anaconda.Navigator GUI关闭并重新启动 Anaconda.Navigator GUI
  • "Quit" the Jupyter server (option found in the browser tab). “退出”Jupyter 服务器(浏览器选项卡中的选项)。 Restarted the server.重新启动服务器。
  • %conda install -c conda-forge nglview at the top of the Notebook. %conda install -c conda-forge nglview在笔记本的顶部。 It just informs me that it's already installed.它只是告诉我它已经安装好了。
  • Closing the tab and all mentions of Anaconda and Jupyter (but not the browser window instance itself).关闭选项卡和所有提及的 Anaconda 和 Jupyter(但不是浏览器 window 实例本身)。

The fact that I haven't restarted the machine itself is a big grey elephant.我还没有重新启动机器本身就是一头灰色的大象。 Unfortunately, it's running a long Quantum chemistry calculation in the background that can't be continued after boot:-( Sorry. But I don't want to get hung up on restarting a machine - it shouldn't come down to that.不幸的是,它在后台运行一个长时间的量子化学计算,启动后无法继续:-(对不起。但我不想在重启机器时挂断电话——它不应该归结为那个。

Check whether the version of ipywidget in your current conda version is above 8.0.0.检查你当前conda版本中ipywidget的版本是否在8.0.0以上。 Because Jupyter notebook is not compatible with the new version of ipywidget .因为 Jupyter notebook 不兼容新版本的ipywidget Thus try the command below to install the older version of ipywidget , then ǹglview` should be properly imported:因此尝试下面的命令来安装旧版本的ipywidget ,然后应该正确导入 ǹglview` :

conda install "ipywidgets <8" -c conda-forge

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM