定制环境jupyter笔记本

时间:2020-06-01 14:00:38

标签: python jupyter-notebook customization watson-studio

我希望为Jupyter笔记本电脑创建一个自定义环境,而不必从会话中安装各种软件包。

按照https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/customize-envs.html上的说明,我按照以下步骤自定义了环境

# Modify the following content to add a software customization to an environment.
# To remove an existing customization, delete the entire content and click Apply.

# Add conda channels below defaults, indented by two spaces and a hyphen.
channels:
  - defaults

# To add packages through conda or pip, remove the comment on the following line.
# dependencies:

# Add conda packages here, indented by two spaces and a hyphen.
# Remove the comment on the following line and replace sample package name with your package name:
  - ffmpeg=4.2.2

# Add pip packages here, indented by four spaces and a hyphen.
# Remove the comments on the following lines  and replace sample package name with your package name.
  - pip:
    - numpy==1.18.0
    - pandas==1.0.3
    - matplotlib==3.1.3

因为我的笔记本和最新版本的pandasnumpymatplotlib中需要mpeg编解码器。

配置是

Environment             Custom env
Creator                 Andrea Chiappo
Language                Python 3.6
Hardware configuration  4 vCPU and 16 GB RAM
Software configuration  Default Python 3.6 + DO

但是,一旦我开始会话,我会尝试

import pandas as pd
print(pd.__version__)

我得到了软件包的默认版本0.24.1

有人知道如何在我的jypter会话中启用此类Python软件包的最新版本吗?非常感谢

1 个答案:

答案 0 :(得分:0)

您需要取消注释# dependencies:行。并随时摆脱所有评论。这将有助于发现YAML格式的缩进问题。试试这个:

dependencies:
  - ffmpeg=4.2.2
  - pip
  - pip:
    - numpy==1.18.0
    - pandas==1.0.3
    - matplotlib==3.1.3

但是从PyPI而不是Anaconda安装numpy和熊猫的更新可能会导致问题。一些Anaconda软件包是为特定版本的numpy构建的,如果替换numpy,可能会出现异常。我建议您在可行的情况下从Anaconda而不是PyPI获取软件包。在Python笔记本中,您可以像这样检查conda会应用哪些更改:

!conda install --dry-run numpy=1.18

与pandas和matplotlib类似。或者,您可以使用同一命令指定所有三个。虽然并不清楚,但是哪个软件包更改会导致依赖更新被引入。

!conda install --dry-run numpy=1.18 pandas=1.0 matplotlib=3.1

我没有尝试过Anaconda是否提供您要安装的确切修订级别。如果没有,或者某些组合不起作用(例如,当Anaconda不再为Python 3.6构建新的软件包版本时),您可以选择是否要使用Anaconda提供的软件,还是从该软件包中获取软件包。 PyPI,希望一切都不会中断。

PS: 在上面的自定义中,我已经添加了pip依赖项作为样式。当pip:未列为依赖项时,较新版本的conda会抱怨有一个pip部分。当我们在WS Cloud中推出新的运行时时,它们将使用较新版本的conda。