priitj / whitedb

WhiteDB memory database
http://whitedb.org/
GNU General Public License v3.0
608 stars 78 forks source link

Python Module won't load (Kubuntu 15.10/Python 3.4) #25

Closed Ironlenny closed 6 years ago

Ironlenny commented 8 years ago

I tried compiling WhiteDB with the Python bindings, but the module won't load.

Here is the steps I took to compile and install:

wget http://whitedb.org/whitedb-0.7.3.tar.g
tar -xvf whitedb-0.7.3.tar.gz 
cd whitedb-0.7.3.tar.gz 
./configure --with-python=/usr/bin/python3 --prefix=/usr/ # python3 is symlinked to python3.4
make
sudo make install

$PYTHONPATH:

$ python3 -c "import sys; print (sys.path)"
['', '/usr/lib/python3.4', '/usr/lib/python3.4/plat-x86_64-linux-gnu', '/usr/lib/python3.4/lib-dynload', '/usr/local/lib/python3.4/dist-packages', '/usr/lib/python3/dist-packages']

Proof files are install:

$ ls /usr/lib/python3.4/site-packages
__pycache__/  WGandalf.py  wgdb.a  wgdb.la*  wgdb.so*  whitedb.py

When I import whitedb, I get:

Traceback (most recent call last):
  File "/home/username/Code/infodump/db.py", line 3, in <module>
    import whitedb
ImportError: No module named 'whitedb'

I tried directly loading the module:

import importlib.machinery
db = importlib.machinery.SourceFileLoader('whitedb', '/usr/lib/python3.4/site-packages/whitedb.py').load_module()

Output:

Traceback (most recent call last):
  File "/home/username/Code/infodump/db.py", line 5, in <module>
    db = importlib.machinery.SourceFileLoader('whitedb', '/usr/lib/python3.4/site-packages/whitedb.py').load_module()
  File "<frozen importlib._bootstrap>", line 539, in _check_name_wrapper
  File "<frozen importlib._bootstrap>", line 1614, in load_module
  File "<frozen importlib._bootstrap>", line 596, in _load_module_shim
  File "<frozen importlib._bootstrap>", line 1220, in load
  File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1129, in _exec
  File "<frozen importlib._bootstrap>", line 1471, in exec_module
  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
  File "/usr/lib/python3.4/site-packages/whitedb.py", line 33, in <module>
    import wgdb
ImportError: No module named 'wgdb'

Any help would be appreciated.

priitj commented 8 years ago

Ouch. I investigated a bit and here's why this happens:

Relatively recent automake versions have been updated to use the sysconfig module to obtain the module path, this is to be more compatible with Python 3.

However, when I run

import sysconfig
sysconfig.get_paths()

on an Ubuntu system, I get module paths with site-packages in them. As far as I know, without extra tweaking, Python on Ubuntu doesn't touch the site-packages directory at all. I suspect the output of sysconfig.get_paths() is similar in your case.

The best fix would be to give up autotools completely and split Python module from the main package. Of course, this is relatively useless information in your particular case :-) I suspect getting a newer automake, Python and the git version of whitedb would also make no difference as long as the output of the sysconfig module differs from the actual sys.path

A quick and relatively simple workaround would be to include the /usr/lib/python3.4/site-packages in module search path on your system. I'll see if anything can be done about the autotools macros, but in that regard the 0.7.3 version will unfortunately remain permanently broken. The macro that checks the Python module path in the way I described above, is already packaged in.

Ironlenny commented 8 years ago

For documentary purposes here is the work-around I'm using:

import sys
sys.path.append("/usr/lib/python3.4/site-packages")
import whitedb
priitj commented 6 years ago

4 will cover this.

Python binding will be split into a separate project.