这些天如何在 google colab 中导入 rdkit?

How to import rdkit in google colab these days?

!wget -c https://repo.continuum.io/miniconda/Miniconda3-py37_4.8.3-Linux-x86_64.sh
!chmod +x Miniconda3-py37_4.8.3-Linux-x86_64.sh
!time bash ./Miniconda3-py37_4.8.3-Linux-x86_64.sh -b -f -p /usr/local
!time conda install -q -y -c conda-forge rdkit

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

:代码来自 <>

上面的代码是 Whosebug 中另一篇关于在 Google Colab 中导入 'rdkit' 的文章的解决方案之一,但它对我不起作用并显示此错误消息:

from rdkit import Chem

ImportError: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.26' not found (required by /usr/local/lib/python3.7/site-packages/rdkit/DataStructs/cDataStructs.so)

有人知道如何解决这个 ImportError: `GLIBCXX_3.4.26' not found 问题吗? 我真诚地需要帮助!非常感谢!

您 link 编辑的答案现在有点过时了。在 Colab 上安装最新版本的 RDKit (2020.09.3) 似乎也存在问题。安装旧版本 (2020.09.2) 似乎可以解决问题:

%%bash
wget -c https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh
chmod +x Miniconda3-latest-Linux-x86_64.sh
./Miniconda3-latest-Linux-x86_64.sh -b -f -p /usr/local
conda config --set always_yes yes --set changeps1 no
conda install -q -y -c conda-forge python=3.7
conda install -q -y -c conda-forge rdkit==2020.09.2 

其次是:

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

如果您必须安装最新版本 (2020.09.3),我通过在 bash 单元格中添加几行找到了解决方法:

%%bash
add-apt-repository ppa:ubuntu-toolchain-r/test
apt-get update --fix-missing
apt-get dist-upgrade
wget -c https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh
chmod +x Miniconda3-latest-Linux-x86_64.sh
./Miniconda3-latest-Linux-x86_64.sh -b -f -p /usr/local
conda config --set always_yes yes --set changeps1 no
conda install -q -y -c conda-forge python=3.7
conda install -q -y -c conda-forge rdkit

为了使这个工作运行时也需要重新启动,我只是在 rdkit 导入周围添加一个 try/except 以自动重新启动运行时:

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

try:
  from rdkit import Chem
  from rdkit.Chem.Draw import IPythonConsole
except ImportError:
  print('Stopping RUNTIME. Colaboratory will restart automatically. Please run cell again.')
  exit()

Colab link 第一个解决方案:https://colab.research.google.com/drive/1vhsLgzA7A_INMcbU-hG6go4M6axvbUpi?usp=sharing

Colab link 第二个解决方案:https://colab.research.google.com/drive/1Ix0oyUU4cA1b2rD9JfkMhy8M2z5Y_vTL?usp=sharing

我认为最好的方法是使用 Jaime Rodríguez-Guerra 和 Alex Malins 的 condacolab。
https://github.com/conda-incubator/condacolab

!pip install -q condacolab
导入 condacolab
condacolab.install()
然后
导入 condacolab
condacolab.check()