如何在Mac上的Colab下从Anaconda内部安装"plotly" [英] How to install 'plotly' from inside Anaconda under Colab on Mac

查看:469
本文介绍了如何在Mac上的Colab下从Anaconda内部安装"plotly"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用代码导入Anaconda中的plotly

I tried to import plotly in Anaconda with code

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)

但收到错误

---------------------------------------------------------------------------
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'

我检查了许多类似的帖子,以在Jupyter上安装'plotly',但是不知为何我无法在Mac上安装它.我通常使用Google Colab,这可能是我使用其他平台导致安装时感到困惑的原因吗?

I have checked a number of similar posts to install 'plotly' on Jupyter but somehow I couldn't do it on Mac. I usually use Google Colab, could it be the reason that I am using different platforms that caused the confusion when installing?

推荐答案

Jupyter笔记本在环境"中启动. Anaconda创建了环境,其中包含许多有用的库.它还拥有一个自包含的python解释器.在这种情况下,该环境没有按规划安装该库(这不是Anaconda提供的默认库),因此您必须在该笔记本所在的环境中按图安装.

Jupyter Notebooks start in an "environment". Anaconda created the environment and it contains a lot of useful libraries. It also holds a self-contained python interpreter. 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.

与Jupyter Notebooks一起使用的环境在安装时有些棘手,因此,通过这种方式,使用import sys然后使用!{sys.executable} -m pip install plotly安装库可以找到!{sys.executable}的python解释器并进行安装直接在笔记本电脑中使用点子.

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.

更多阅读内容:

  • Environments
  • Pip
  • Packages included with Anaconda

尝试:

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)

这篇关于如何在Mac上的Colab下从Anaconda内部安装"plotly"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆