在 Deepnote 上安装 Conda

Installing Conda on Deepnote

我是一个相当缺乏经验的程序员,正在努力将 Conda 安装到 Deepnote. Pip install doesn't work for certain packages. For example, I'm trying to install rdkit, a cheminformatics package, which has rather complex installation instructions 或通过 Anaconda/mini-conda 发行版管理的简单的 1 行代码。我真的很喜欢 Deepnote 笔记本,如果有任何帮助,我将不胜感激。

到目前为止,我已经在 Google Colab 上找到了用于安装 Conda 的有用代码:https://github.com/dataprofessor/code/blob/master/python/google_colab_install_conda.ipynb

! wget https://repo.anaconda.com/miniconda/Miniconda3-py37_4.8.2-Linux-x86_64.sh
! chmod +x Miniconda3-py37_4.8.2-Linux-x86_64.sh
! bash ./Miniconda3-py37_4.8.2-Linux-x86_64.sh -b -f -p /usr/local
import sys
sys.path.append('/usr/local/lib/python3.7/site-packages/')

虽然这在 Google Colab 上成功运行,但我不确定为什么它会失败,如下所示在 Deepnote 上:

--2020-12-04 22:58:34--  https://repo.anaconda.com/miniconda/Miniconda3-py37_4.8.2-Linux-x86_64.sh
Resolving repo.anaconda.com (repo.anaconda.com)... 104.16.130.3, 104.16.131.3, 2606:4700::6810:8203, ...
Connecting to repo.anaconda.com (repo.anaconda.com)|104.16.130.3|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 85055499 (81M) [application/x-sh]
Saving to: ‘Miniconda3-py37_4.8.2-Linux-x86_64.sh’

Miniconda3-py37_4.8 100%[===================>]  81.12M   133MB/s    in 0.6s    

2020-12-04 22:58:35 (133 MB/s) - ‘Miniconda3-py37_4.8.2-Linux-x86_64.sh’ saved [85055499/85055499]

PREFIX=/usr/local
./Miniconda3-py37_4.8.2-Linux-x86_64.sh: line 392: /usr/local/conda.exe: Permission denied
chmod: cannot access '/usr/local/conda.exe': No such file or directory
Unpacking payload ...
./Miniconda3-py37_4.8.2-Linux-x86_64.sh: line 404: /usr/local/conda.exe: No such file or directory
./Miniconda3-py37_4.8.2-Linux-x86_64.sh: line 406: /usr/local/conda.exe: No such file or directory

我也想安装 conda install -c bioconda gromacs,但我找不到解决方法,所以我希望有人能帮我解决这个问题。

非常感谢!

P.S。我在 Mac OS

您可以查看 Daniel Zvara 的笔记本

Using Conda in Deepnote in 3 simple steps

总之

# 1. Install Conda and make Conda packages available in current environment

!wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
!chmod +x Miniconda3-latest-Linux-x86_64.sh
!sudo bash ./Miniconda3-latest-Linux-x86_64.sh -b -f -p /usr/local

import sys
sys.path.append('/usr/local/lib/python3.7/site-packages/')

# 2. Package installation
# !sudo conda install -y [EXTRA_OPTIONS] package_name

# So for example Keras from conda-forge channel
!sudo conda install -y -c conda-forge keras

# 3. Package usage

import keras

还在Deepnote社区找到了替代方案:https://community.deepnote.com/c/custom-environments/custom-environment-for-installing-conda-packages

可以使用以下Dockerfile设置自定义环境(只需填写您需要的包的占位符)。

FROM gcr.io/deepnote-200602/templates/deepnote
RUN wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda.sh
RUN bash ~/miniconda.sh -b -p $HOME/miniconda
ENV PATH $HOME/miniconda/bin:$PATH
RUN conda install python=3.7 ipykernel -y
RUN conda install <insert packages here> -y
RUN python -m ipykernel install --user --name=conda
ENV DEFAULT_KERNEL_NAME "conda"

Deepnote 中的自定义环境是通过侧边栏中的“环境”选项卡设置的,为您提供了 Dockerfile 选项。复制并粘贴上面的内容,然后单击构建并重新启动机器 - 环境将设置为允许您使用 conda。