Unable to use RDKit in Jupyter or iPython - python

I want to use RDKit in a Jupyter environment. However, after I followed the procedure outlined in this document.
After following the process, including getting the kernel for jupyter, I tried to access RDKit and play with it.
(rdkit-test) [user] ~ $ python
Python 3.7.9 (default, Aug 31 2020, 07:22:35)
[Clang 10.0.0 ] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.executable
'/Users/user/opt/anaconda3/envs/rdkit-test/bin/python'
>>> import rdkit
>>>
[6]+ Stopped python
Right from test anaconda environment rdkit-test, it seems like I can access rdkit and test with it.
Now, I try to access it via iPython:
(rdkit-test) [user] ~ $ ipython
Python 3.8.7 (v3.8.7:6503f05dd5, Dec 21 2020, 12:45:15)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.17.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: import sys
In [2]: sys.executable
Out[2]: '/Library/Frameworks/Python.framework/Versions/3.8/bin/python3.8'
In [3]: import rdkit
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-3-6b72bd8913ab> in <module>
----> 1 import rdkit
ModuleNotFoundError: No module named 'rdkit'
I can't seem to access rdkit. I can also see that I am not in the write environment, from my sys.executable command.
The same problem I see in a Jupyter notebook:
How do I fix this and use RDKit in Jupyter or iPython?

You should use !pip install kora. Then, use import kora.install.rdkit.

Related

Cant import pandas in Blender

I am trying to import pandas in blender but it's not finding the module.
I have checked that Blender has the correct paths and looks like it is.
This is my output in blender:
>>> print(sys.path)
['/usr/share/blender/2.93/scripts/startup', '/usr/share/blender/2.93/scripts/modules', '/usr/lib/python39.zip', '/usr/lib/python3.9', '/usr/lib/python3.9/lib-dynload', '/usr/lib/python3.9/site-packages', '/usr/lib/python3.9/site-packages/evtk-2.0.0-py3.9.egg', '/usr/share/blender/2.93/scripts/freestyle/modules', '/usr/share/blender/2.93/scripts/addons/modules', '/home/jjcasmar/.config/blender/2.93/scripts/addons/modules', '/usr/share/blender/2.93/scripts/addons', '/home/jjcasmar/.config/blender/2.93/scripts/addons', '/usr/share/blender/2.93/scripts/addons_contrib']
>>> print(sys.version)
3.9.7 (default, Aug 31 2021, 13:28:12)
[GCC 11.1.0]
>>> print(sys.path)
['/usr/share/blender/2.93/scripts/startup', '/usr/share/blender/2.93/scripts/modules', '/usr/lib/python39.zip', '/usr/lib/python3.9', '/usr/lib/python3.9/lib-dynload', '/usr/lib/python3.9/site-packages', '/usr/lib/python3.9/site-packages/evtk-2.0.0-py3.9.egg', '/usr/share/blender/2.93/scripts/freestyle/modules', '/usr/share/blender/2.93/scripts/addons/modules', '/home/jjcasmar/.config/blender/2.93/scripts/addons/modules', '/usr/share/blender/2.93/scripts/addons', '/home/jjcasmar/.config/blender/2.93/scripts/addons', '/usr/share/blender/2.93/scripts/addons_contrib']
>>> import pandas
Traceback (most recent call last):
File "<blender_console>", line 1, in <module>
ModuleNotFoundError: No module named 'pandas'
And this is the output if I just launch a python environment from my virtual terminal
[jjcasmar#archlinux ~]$ python
Python 3.9.7 (default, Aug 31 2021, 13:28:12)
[GCC 11.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print(sys.version)
3.9.7 (default, Aug 31 2021, 13:28:12)
[GCC 11.1.0]
>>> print(sys.path)
['', '/usr/lib/python39.zip', '/usr/lib/python3.9', '/usr/lib/python3.9/lib-dynload', '/home/jjcasmar/.local/lib/python3.9/site-packages', '/usr/lib/python3.9/site-packages', '/usr/lib/python3.9/site-packages/evtk-2.0.0-py3.9.egg']
>>> import pandas as pd
>>>
My blender environment has the correct paths and the versions are the same, but it fails to import pandas. What is wrong here?
Have you installed the lib? Try pip install pandas
Have you activated your virtual environment?
Maybe you could try to install pandas directly from the blender's pip environment ?
Open a python interactive console in blender then:
import pip
pip.main(['install','pandas==1.4.0'])
Then as you did you can try to import pandas to see if it works:
import pandas as pd
(On my side i tested on MacosX only but it works)

Different python version Jupyter Notebook linux terminal, can't find module in jupyter, but able to do that in terminal

I have a problem. I use anaconda and make an environment. I check python in my terminal and everything is ok.
(anaconda_env) jakub#jakub-Z370-HD3P:/media/jakub/WD/EnerPres_g2020_2/bez_zmian/POPC_300K_11_01_2021_bez_zmian_parametrow/calc_order$ python
Python 3.9.1 (default, Dec 11 2020, 14:32:07)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas as pd
>>> import numpy as np
>>> import MDAnalysis as mda
>>>
But when I run Jupyter notebook by write in terminal
(anaconda_env) jakub#jakub-Z370-HD3P:/media/jakub/WD/EnerPres_g2020_2/bez_zmian/POPC_300K_11_01_2021_bez_zmian_parametrow/calc_order$ jupyter-notebook
I have problems
from platform import python_version
print(python_version())
3.7.1
import pandas as pd
import numpy as np
import MDAnalysis as mda
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-7-c040e9ed8c6a> in <module>
1 import pandas as pd
2 import numpy as np
----> 3 import MDAnalysis as mda
ModuleNotFoundError: No module named 'MDAnalysis'
Why I can't import modules and why the Jupyter Python version is different?
Edit:
I found the solution, I just installed on that environment jupyter again:
(anaconda_env) jakub#jakub-Z370-HD3P:/media/jakub/WD/EnerPres_g2020_2/bez_zmian/POPC_300K_11_01_2021_bez_zmian_parametrow/calc_order$ pip install jupyter
This is likely/often that the jupyter installation isn't in the same conda environment as the modules you want to import. Try "conda install jupyter" from the environment which has the modules you want to import inside jupyter.
In my case,
conda update -n base -c defaults conda
conda activate <Your Environment Name>
conda install jupyter
(included ipykernel)
IN jupyter notebook, ipython,
import sys
sys.version
You can check your same version with your shell's python version.

How can I use globally installed CV2 (manual install) package into python virtual environment?

I have manually installed CV2 on Ubuntu box, and when I import CV2 it works perfectly.
If I create virtual environment (python -m venv myvenv), I am not able to use globally installed CV2.
Kindly advice the fix, to use global installed packages into python virtual environment.
Python 3.8.5 (default, Jul 28 2020, 12:59:40)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2 as cv
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'cv2'
>>>

Very odd python vs. ipython discrepancy

I am currently scratching my head on differing behavior for python and ipython.
Background: I want to play with tensorflow, and following the instructions of some online resources, I installed anaconda3 which would take care about everything. I am not particularly familiar with anaconda and just followed the instructions.
Now, I created a virtual environment (xyzzy in the example below). Then, within this environment, I invoked an interactive python shell and tried to import numpy, pandas and tensorflow.
(xyzzy) countermode#peppermint:~$ python
Python 3.6.6 |Anaconda, Inc.| (default, Jun 28 2018, 17:14:51)
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas as pd
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pandas'
>>> import numpy as np
>>> import tensorflow as tf
>>>
Well, ok, it seems that pandas is somehow not accessible, although it actually is installed.
Anyway, now the same with ipython:
(xyzzy) countermode#peppermint:~$ ipython
Python 3.6.6 |Anaconda custom (64-bit)| (default, Jun 28 2018, 17:14:51)
Type 'copyright', 'credits' or 'license' for more information
IPython 6.5.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: import pandas as pd
In [2]: import numpy as np
In [3]: import tensorflow as tf
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-3-64156d691fe5> in <module>()
----> 1 import tensorflow as tf
ModuleNotFoundError: No module named 'tensorflow'
So now the pandas import works fine while tensorflow appears to be gone.
Ummm... what is going on here? Why do I see this behavior? And how can I resolve it?
Supplementary information
This all happens on Linux Mint, the system is updated, anaconda and all packages maintained by it are updated, all packages within the environment are updated. I did not meddle with anything.
Conclusion
After installing ipython in the virtual environment both shells "agreed" on their behavior.
This question is possibly a duplicate of/relates to this .
You probably installed ipython globally and are therefor not using the virtual environment. To fix this:
activate venv
install ipython within the venv using pip
If the venv is activated, it should now use the ipython version within the venv.

python module import error when running, while imported fine in interactive mode

I've created a clean python3.6 virtualenv in a native python2 environment via anaconda3, and I'm able to import some module in the interactive mode:
$ python
Python 3.6.3 |Anaconda, Inc.| (default, Oct 13 2017, 12:02:49)
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from skimage.transform import resize
>>>
however, this seems to break when I run in a non-interactive mode by calling:
(py3)$ python filename.py
...
File "path_to_module.py", line 6, in <module>
from skimage.transform import resize
...
ImportError: /usr/lib64/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by path_to_pyenv/anaconda3/lib/python3.6/site-packages/matplotlib/_path.cpython-36m-x86_64-linux-gnu.so)
Note this error does not occur exclusively by importing this particular skimage module, so i guess this is a generic error.
Anyone has an idea how to fix this?
Thanks!
turns out that the native matplotlib coming with Anaconda was outdated, so i fixed this error by upgrading it:
pip install matplotlib --upgrade

Categories