简体   繁体   English

如何在 Mac 上的 Colab 下从 Anaconda 内部安装“plotly”

[英]How to install 'plotly' from inside Anaconda under Colab on Mac

I tried to import plotly in Anaconda with code我试图导入plotlyAnaconda的代码

import plotly.graph_objs as go
from plotly import __version__
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
init_notebook_mode(connected=True)

but received error但收到错误

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-11-978bd9a5088a> in <module>
     14 
     15 # import plotly.plotly as py
---> 16 import plotly.graph_objs as go
     17 from plotly import __version__
     18 from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot

ModuleNotFoundError: No module named 'plotly'

I have checked a number of similar posts to install 'plotly' on Jupyter but somehow I couldn't do it on Mac.我已经检查了许多类似的帖子以在Jupyter上安装'plotly' ,但不知何故我无法在 Mac 上做到这一点。 I usually use Google Colab, could it be the reason that I am using different platforms that caused the confusion when installing?我平时用的是Google Colab,会不会是我用的平台不同导致安装混乱的原因?

Jupyter Notebooks start in an "environment". Jupyter Notebooks 从一个“环境”开始。 Anaconda created the environment and it contains a lot of useful libraries. Anaconda 创建了环境,其中包含许多有用的库。 It also holds a self-contained python interpreter.它还拥有一个独立的 Python 解释器。 In this instance, the environment didn't have the library plotly installed (it's not a default library that Anaconda provides) so you had to install plotly in your environment that the notebook lives in.在这种情况下,环境没有 plotly 安装库(它不是 Anaconda 提供的默认库),因此您必须在 notebook 所在的环境中安装 plotly。

The environments that are used with Jupyter Notebooks are a little tricky to get to in order to install things, so this way, using import sys then installing the library with !{sys.executable} -m pip install plotly finds the python interpreter with !{sys.executable} and installs plotly using pip right in the Notebook itself.与 Jupyter Notebooks 一起使用的环境为了安装东西有点棘手,所以这样,使用import sys然后使用!{sys.executable} -m pip install plotly找到 python 解释器!{sys.executable}并在 Notebook 本身中使用 pip 进行!{sys.executable}安装。

More reading:更多阅读:

try:尝试:

import sys
!{sys.executable} -m pip install plotly
import plotly.graph_objs as go
from plotly import __version__
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
init_notebook_mode(connected=True)

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

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