[英]customise environment jupyter notebook
我希望為我的 Jupyter 筆記本創建一個自定義環境,而不必從 session 中安裝各種包。
按照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
因為我的筆記本和最新版本的pandas
、 numpy
和matplotlib
需要 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
但是,一旦我啟動 session,如果我嘗試
import pandas as pd
print(pd.__version__)
我得到了 package 的默認版本,即0.24.1
。
有人知道如何在我的 jypter session 中啟用此類 Python 軟件包的更新版本嗎? 非常感謝
您需要取消注釋# dependencies:
行。 並隨時擺脫所有評論。 這將有助於發現 YAML 格式的縮進問題。 嘗試這個:
dependencies:
- ffmpeg=4.2.2
- pip
- pip:
- numpy==1.18.0
- pandas==1.0.3
- matplotlib==3.1.3
但是從 PyPI 而不是 Anaconda 安裝 numpy 和 pandas 的更新可能會導致問題。 一些 Anaconda 包是為特定版本的 numpy 構建的,如果更換 numpy,可能會出現異常。 我建議您在可行的情況下從 Anaconda 而不是 PyPI 獲取軟件包。 在 Python 筆記本中,您可以檢查conda
將應用哪些更改,如下所示:
!conda install --dry-run numpy=1.18
pandas 和 matplotlib 也是如此。 或者您使用相同的命令指定所有三個。 盡管 package 更改中的哪一個會導致引入依賴項更新,但這並不明顯。
!conda install --dry-run numpy=1.18 pandas=1.0 matplotlib=3.1
我沒有嘗試是否可以從 Anaconda 獲得您要安裝的確切修復級別。 If not, or if certain combinations don't work (for example when Anaconda doesn't build a new package version for Python 3.6 anymore), it's you choice whether you want to go with what Anaconda provides, or whether to get the package from PyPI 並希望沒有任何問題。
PS:在上面的自定義中,我添加了pip
依賴項作為樣式問題。 當pip
未被列為依賴項時,較新版本的 conda 將抱怨有pip:
部分。 當我們在 WS Cloud 中推出新的運行時,它們將使用更新版本的 conda。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.