How to import rdkit in google colab these days? - importerror

!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/')
: The code from <Installing RDKit in Google Colab>
The code above is one of the solutions from another article in stackoverflow on importing 'rdkit' in Google Colab, but it didn't work for me with this error message:
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)
Does anybody know how to solve this ImportError: `GLIBCXX_3.4.26' not found problem?
I sincerely need help! Big thx!

The answer you linked is a little outdated now. Seems like there is also an issue with installing the latest build of the RDKit (2020.09.3) on Colab. Installing the older version (2020.09.2) seems to solve the issue:
%%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
Followed by:
import sys
sys.path.append('/usr/local/lib/python3.7/site-packages/')
from rdkit import Chem
If you must install the latest build (2020.09.3), I have found a workaround by adding a few lines to the bash cell:
%%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
To make this work the runtime also will need to be restarted, I just add a try/except around the rdkit import to restart the runtime automatically:
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 for the first solution: https://colab.research.google.com/drive/1vhsLgzA7A_INMcbU-hG6go4M6axvbUpi?usp=sharing
Colab link for the second solution: https://colab.research.google.com/drive/1Ix0oyUU4cA1b2rD9JfkMhy8M2z5Y_vTL?usp=sharing

I think the best way of doing that is to use condacolab by Jaime Rodríguez-Guerra and Alex Malins.
https://github.com/conda-incubator/condacolab
!pip install -q condacolab
import condacolab
condacolab.install()
then
import condacolab
condacolab.check()

Well one simple trick is to install deepchem and it comes with rdkit
!pip install deepchem
from rdkit import Chem

Related

Issue while installing Scipy

I installed Scipy using the command sudo apt-get install python-numpy python-scipy and looks like the latest version of both are installed. But when I try to install a python package named wfdb using pip install wfdb, it get an error while Building wheel for scipy (PEP 517).
ERROR: Failed building wheel for scipy
Running setup.py clean for scipy
ERROR: Command errored out with exit status 1:
command: /usr/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] =
'"'"'/tmp/pip-install-
fhfmfpqi/scipy/setup.py'"'"'; __file__='"'"'/tmp/pip-install-
fhfmfpqi/scipy/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)
(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code,
__file__,
'"'"'exec'"'"'))' clean --all
cwd: /tmp/pip-install-fhfmfpqi/scipy
Complete output (9 lines):
`setup.py clean` is not supported, use one of the following instead:
- `git clean -xdf` (cleans all files)
- `git clean -Xdf` (cleans all versioned files, doesn't touch
files that aren't checked into the git repo)
Add `--force` to your command to use it anyway if you must (unsupported).
----------------------------------------
ERROR: Failed cleaning build dir for scipy
Failed to build scipy
ERROR: Could not build wheels for scipy which use PEP 517 and cannot be installed directly`
I upgraded pip using pip install --upgrade pip.
python version used: 3.7
Can I get some help on this?
Clean out the install (I don't know which system you're using) i.e. get rid of the $PATH variables and just do a fresh install.
If you're using Anaconda:
conda install -c anaconda scipy
should do it
also the goops old
pip install scipy
gets it done as well. May I ask why you approached your installation in this way (again, I don't know which system you're on)
Never do sudo pip. Instead do pip install --user. Or (better) work in a virtualenv.
EDIT: typo: there is no space between -- and user.

EMR PySpark "ModuleNotFoundError: No module named 'spacy'"

I've been unsuccessfully trying to install Spacy onto my EMR cluster to run a Pyspark job.
My Bootstrapping actions to EMR look something like this
pip install --upgrade pip
sudo conda install -c conda-forge spacy
sudo python3 -m spacy download en_core_web_sm
sudo python3 -m spacy download en
sudo python3 -m pip install -U spacy
sudo python3 -m pip install -U boto3
sudo python3 -m pip install -U pandas
sudo python3 -m spacy download en_core_web_sm
sudo python3 -m spacy download en
As you see above i've been trying to install it via pip and conda both but none seem to work.
Suprisingly when I use a jupyter notebook and not try to submit my pyspark job as a step to EMR it works.
I had faced a similar problem. Some of the things that could work:
Check the stdout, stderr files in EMR, on bootstrap actions. It's mentioned under the summary section of the cluster-Configuration details-LOG URI
Apparently, Spacy has Cython dependency and it's not downloaded automatically. Thus including the following commands helped:
sudo python3 -m pip install --upgrade pip
sudo python3 -m pip install --upgrade pip setuptools
sudo python3 -m pip install wheel
sudo python3 -m pip install -U Cython
sudo python3 -m pip install -U spacy==2.3.5
sudo python3 -m spacy download en_core_web_sm

Installing Network-x

How do I download and install network-x for python version 3.4.0 on mac? Can someone give me a step by step guide on installing network-x? I tried to quick 'quick install' as suggested by github.
When I try to import it on python it gives me an import error saying no modules were found.
Ok so I have figured out an easier way:
(Answering my own question)
I first download the networkx-1.10.zip (md5) zip file from https://pypi.python.org/pypi/networkx. Unzipped it. Opened the terminal and typed cd
Then, I dragged and dropped the unzipped folder (networkx-1.10) into the terminal. Hit Enter.
Then I proceeded with the following commands:
python3 --version
ls
umask
sudo python setup.py install
sudo python3 setup.py install
python3
It worked like a charm.
this has worked for me
sudo pip install networkx
This should work:
sudo pip3 install networkx
if you have annaconda, in your terminal or cmd
> % conda install -c anaconda networkx
> % conda install -c anaconda graphviz
> % conda install -c anaconda pydot
> % conda install -c pdrops pygraphviz
The other packages come in handy as well
The easiest way is using Anaconda, since networkX is installed by default. Just follow the instructions on their website (they have both a graphical and command line installer).

pip - Requirement already satisfied?

pip recognize global installed packages..?! :-(
I've used virtualenvwrapper preactivate hook to clean PYTHONPATH,
export PYTHONPATH=""
then echo $PYTHONPATH returns empty string, but this didn't help.
What's wrong?
bentzy#lama:~$ mkvirtualenv test
New python executable in test/bin/python
Installing setuptools............done.
Installing pip...............done.
virtualenvwrapper.user_scripts creating /home/bentzy/.virtualenvs/test/bin/predeactivate
virtualenvwrapper.user_scripts creating /home/bentzy/.virtualenvs/test/bin/postdeactivate
virtualenvwrapper.user_scripts creating /home/bentzy/.virtualenvs/test/bin/preactivate
virtualenvwrapper.user_scripts creating /home/bentzy/.virtualenvs/test/bin/postactivate
virtualenvwrapper.user_scripts creating /home/bentzy/.virtualenvs/test/bin/get_env_details
(test)bentzy#lama:~$ which pip
/home/bentzy/.virtualenvs/test/bin/pip
(test)bentzy#lama:~$ sudo pip install simplejson
Requirement already satisfied (use --upgrade to upgrade): simplejson in /usr/lib /python2.7/dist-packages
Cleaning up...
(test)bentzy#lama:~$ echo $PYTHONPATH
(test)bentzy#lama:~$ pip --version
pip 1.2.1 from /home/bentzy/.virtualenvs/test/lib/python2.7/site-packages/pip-1.2.1-py2.7.egg (python 2.7)
You are using sudo to install simplejson, but if you use sudo your $PATH may be changed, and that seems to be the problem.
Just use pip install simplejson (no sudo included) and it is probably going to work.
Use sudo only when you want to affect your whole system.
Already satisfied means that you already install "it".
try:
pip uninstall simplejson
and then:
pip install simplejson

scipy missing libifport.so.5

I am trying to install scipy 0.10.1 on Ubuntu 10.10 using pip.
I have successfully installed numpy:
$ sudo pip install --upgrade numpy
[snip]
Successfully installed numpy
Cleaning up...
but when I try scipy I get:
$ sudo pip install --upgrade scipy
[snip]
File "/usr/local/lib/python2.6/dist-packages/numpy/linalg/linalg.py", line 23, in <module>
from numpy.linalg import lapack_lite
ImportError: libifport.so.5: cannot open shared object file: No such file or directory
I do have libifport.so.5, but I don't know why the installer isn't finding it.
$ echo $LD_LIBRARY_PATH
:/opt/intel/composerxe-2011.2.137/compiler/lib/intel64
I have also tried to install several other packages in the hope that one of them might help (e.g. libatlas-base-dev liblapack-dev libatlas-base-dev liblapack-dev, etc)
Any thoughts?
Thank you.
Most likely you have not defined the LD_LIBRARY_PATH for root. To check this:
$ sudo su
$echo $LD_LIBRARY_PATH
You can specify environment variables as follows:
$ sudo env LD_LIBRARY_PATH=path/to/compiler' pip install scipy
Check out this blog post to create an alias to save you typing each time:
http://final-world-domination.blogspot.ch/2011/02/sudo-doesnt-export-ldlibrarypath.html
This fixed the problem for me on Debian 9:
conda install -c intel -c conda-forge -c pytorch --override-channels intel-fortran-rt
# find / -iname "libifport*"
./opt/conda/lib/libifport.so
./opt/conda/lib/libifport.so.5
./opt/conda/pkgs/intel-fortran-rt-2021.3.0-intel_3350/lib/libifport.so
./opt/conda/pkgs/intel-fortran-rt-2021.3.0-intel_3350/lib/libifport.so.5