Accessing Python Modules Installed with Brew - python

I am trying to access "rdkit" module in python, but my python install doesn't seem to find the module. I installed it using brew as suggested here. I included the commands I use to reproduce the problem.
Is a simple fix just adding the "/usr/local/Cellar" to the python path? Symlinc the site-packages to the cellar? Candidly I did not understand the difference between pip and brew when updating my python, so my first thought is that the python path is not correct. Any suggestions greatly appreciated.
X:~\ python3 Python 3.8.1 (v3.8.1:1b293b6006, Dec 18 2019, 14:08:53) [Clang 6.0 (clang-600.0.57)] on darwin Type "help", "copyright", "credits" or "license" for more information.
>>> import rdkit Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'rdkit'
X:~\ which python3
/Library/Frameworks/Python.framework/Versions/3.8/bin/python3
X:~\ python3
Python 3.8.1 (v3.8.1:1b293b6006, Dec 18 2019, 14:08:53)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print(sys.path)
['',
'/Library/Frameworks/Python.framework/Versions/3.8/lib/python38.zip',
'/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8',
'/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/lib-dynload',
'/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages']
**#:/usr/local/Cellar\** ls
boost/ gettext/ libffi/ numpy/ sip/
boost-python3/ glew/ libidn2/ openblas/ sqlite/
cmake/ glib/ libmpc/ openssl#1.1/ tcl-tk/
ddclient/ glm/ libpng/ pandoc/ tree/
eigen/ gmp/ libtiff/ pcre/ webp/
fontconfig/ graphviz/ libtool/ pkg-config/ wget/
freeglut/ gts/ libunistring/ pyqt/ xz/
freetype/ icu4c/ mmtf-cpp/ python/
gcc/ isl/ mpfr/ qt/
gd/ jasper/ msgpack/ **rdkit/**
gdbm/ jpeg/ netpbm/ readline/
Details:
OS Catalina: 10.15.3

Related

ModuleNotFoundError: No module named 'psycopg2._psycopg' (Ipython)

This question has been asked before but none of the answers are satisfactory.
Using Command Prompt on Windows 10, there is no issue importing Psycopg2, which is located in
C:\Users\myusername\AppData\Roaming\Python\Python39\site-packages
For example:
Python 3.9.1 (tags/v3.9.1:1e5d33e, Dec 7 2020, 17:08:21) [MSC v.1927 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import psycopg2
>>>
In the IPython console of Spyder, I get an error:
Python 3.7.9 (tags/v3.7.9:13c94747c7, Aug 17 2020, 18:58:18) [MSC v.1900 64 bit (AMD64)]
Type "copyright", "credits" or "license" for more information.
IPython 7.19.0 -- An enhanced Interactive Python.
In [1]: import psycopg2
Traceback (most recent call last):
File "<ipython-input-1-7d2da0a5d979>", line 1, in <module>
import psycopg2
File "C:\Users\myusername\AppData\Roaming\Python\Python39\site-packages\psycopg2\__init__.py", line 51, in <module>
from psycopg2._psycopg import ( # noqa
ModuleNotFoundError: No module named 'psycopg2._psycopg'
Running sys.path indicates that the location of the package installation is there.
In [4]: sys.path
Out[4]:
['C:\\Program Files\\Spyder\\Python\\python37.zip',
'C:\\Program Files\\Spyder\\Python',
'C:\\Program Files\\Spyder\\pkgs',
'C:\\Program Files\\Spyder\\pkgs\\IPython\\extensions',
'C:\\Users\\myusername\\AppData\\Roaming\\Python\\Python39\\site-packages\\psycopg2',
'',
'C:\\Users\\myusername\\AppData\\Roaming\\Python\\Python39\\site-packages',
'C:\\Users\\myusername\\.ipython']
What do I need to do to make this work? It only recently started happening when I reset Windows 10 (uninstalls the operating system and reinstalls it from the cloud, while keeping your files).
This is a standalone installation of Spyder without Anaconda.
As we can see in your path, you have two versions of python installed in your machine.
One points to:
C:\Users\myusername\AppData\Roaming\Python\Python39\site-packages
which is python 3.9.
Another contains the spider code, which is python 3.7.
You just have to install your Psycopg2 in python 3.7 instance.

Make Python module available for all Linux users

I have a Python 2.7 question, if somebody can help.
When we install a Python module using pip, how do we make it available to all users? Please, see the example below (with module faker). The import works when I am root, but doesn’t work when I am ubuntu user.
I have already tried to install using option --system, and also changing umask, as recommended in some articles I have found. Didn’t work so far. Any ideas?
If we run "which python", both users point to the same one.
root#ip-172-30-244-157:/home/ubuntu#
root#ip-172-30-244-157:/home/ubuntu# python
Python 2.7.17 (default, Sep 30 2020, 13:38:04)
[GCC 7.5.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import faker
>>>
>>> exit()
root#ip-172-30-244-157:/home/ubuntu#
root#ip-172-30-244-157:/home/ubuntu#
root#ip-172-30-244-157:/home/ubuntu# exit
exit
ubuntu#ip-172-30-244-157:~$
ubuntu#ip-172-30-244-157:~$
ubuntu#ip-172-30-244-157:~$ python
Python 2.7.17 (default, Sep 30 2020, 13:38:04)
[GCC 7.5.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import faker
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named faker
>>>
Ok, I solved the issue.
In my case, the problematic module was "faker". But, when we install the faker, another additional module is installed as well (in this case - text-unidecode).
Then I uninstalled both modules, ran "umask 022" and re-installed the faker.
This solved the issue for all other users.
Thanks all for the help!

How to use mechanize in pypy?

I used mechanize in Python, but peppy said
$ pypy
Python 2.7.9 (9c4588d731b7fe0b08669bd732c2b676cb0a8233, Mar 31 2015, 07:55:22)
[PyPy 2.5.1 with GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>> import mechanize
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named mechanize
>>>> import sys
>>>> sys.path
['', '/usr/local/Cellar/pypy/2.5.1/libexec/site-packages/setuptools-14.3.1-py2.7.egg', '/usr/local/Cellar/pypy/2.5.1/libexec/site-packages/pip-6.0.8-py2.7.egg', '/usr/local/Cellar/pypy/2.5.1/libexec/lib_pypy/__extensions__', '/usr/local/Cellar/pypy/2.5.1/libexec/lib_pypy', '/usr/local/Cellar/pypy/2.5.1/libexec/lib-python/2.7', '/usr/local/Cellar/pypy/2.5.1/libexec/lib-python/2.7/lib-tk', '/usr/local/Cellar/pypy/2.5.1/libexec/lib-python/2.7/plat-darwin', '/usr/local/Cellar/pypy/2.5.1/libexec/lib-python/2.7/plat-mac', '/usr/local/Cellar/pypy/2.5.1/libexec/lib-python/2.7/plat-mac/lib-scriptpackages', '/usr/local/Cellar/pypy/2.5.1/libexec/site-packages']
Please tell me how to use mechanize in pypy.
I think I haven't create path but I don't know way.
PyPy does not automatically pick CPython paths. You either need to install mechanize separately (I suggest virtualenv) or you need to put path to it into sys.path or PYTHONPATH environment variable.

Only able to import python module inside the installation directory

I installed 64bit package of cefpython in Ubuntu 12.04 LTS (http://code.google.com/p/cefpython/). The problem is I am not able to run the examples. It says no module named wx.
But when I navigate to the directory /usr/local/lib/python2.7/dist-packages/cefpython1 and do import wx it works. So basically I am not able to import wx outside that directory. I am using python interpreter on terminal.
rishi:cefpython1 ls
cefclient cefpython_py27.pyc chrome.pak examples __init__.pyc LICENSE.txt wx
cefpython_py27.py cefpython_py27.so devtools_resources.pak __init__.py libcef.so locales
rishi:cefpython1 python
Python 2.7.3 (default, Sep 26 2013, 20:03:06)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import wx
>>>
[2]+ Stopped python
rishi:cefpython1 cd ..
rishi:dist-packages python
Python 2.7.3 (default, Sep 26 2013, 20:03:06)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import wx
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named wx
>>>
KeyboardInterrupt
>>>
My PATH is as follows and PYTHONPATH is empty:
installed 64bit package of cefpython in Ubuntu 12.04 LTS (http://code.google.com/p/cefpython/). The problem is I am not able to run the examples. It says no module named wx. But when I navigate to the directory /usr/local/lib/python2.7/dist-packages/cefpython1 and do import wx it works. So basically I am not able to import wx outside that directory. I am using python interpreter on terminal.
rishi:dist-packages echo $PATH
/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
rishi:dist-packages echo $PYTHONPATH
rishi:dist-packages echo $PYTHONPATH
rishi:dist-packages
Your problem here is that python has no idea where you are importing from. Refer to This post for instructions. Basically, what is happening is that when you're in the directory, python knows to look for it (it looks for python files and packages in the directory). You need to add the python libraries into the PYTHONPATH.

Compile Z3python?

I want to have Z3python on my Ubuntu 12.04 64-bit. I downloaded Z3 source, and compiled like below:
$autoconf
$./configure
$sudo make
$sudo make a
$sudo make o
Everything went well, but then I tried:
$ python
Python 2.7.3 (default, Sep 26 2012, 21:51:14)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import z3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named z3
It seems Z3python is not installed yet? I followed exactly the instructions in README, but it seems to miss something regarding Python binding?
please ignore, what i got is the old version of Z3.
a recommendation: please provide the source code of the latest Z3 in the homepage. i couldnt find it anywhere, then wrongly got the old version. finally, i had to download the latest version from the SourceControl, which was a bit tricky.

Categories

Resources