coleifer / pysqlite3

SQLite3 DB-API 2.0 driver from Python 3, packaged separately, with improvements
zlib License
192 stars 53 forks source link

'no module' when building a statically-linked library #79

Closed strangerinusall closed 1 month ago

strangerinusall commented 1 month ago

Hi, when on my MacOs I follow the 'Building a statically-linked library' process I end up with this error (after runing a simple test) case:

from pysqlite3 import dbapi2 as sqlite3
print(sqlite3.sqlite_version) 
Traceback (most recent call last):
  File "/Users/username/Sandbox/sqlite3ttt/pysqlite3/a.py", line 1, in <module>
    from pysqlite3 import dbapi2 as sqlite3
  File "/Users/username/Sandbox/sqlite3ttt/pysqlite3/pysqlite3/__init__.py", line 23, in <module>
    from pysqlite3.dbapi2 import *
  File "/Users/username/Sandbox/sqlite3ttt/pysqlite3/pysqlite3/dbapi2.py", line 28, in <module>
    from pysqlite3._sqlite3 import *
ModuleNotFoundError: No module named 'pysqlite3._sqlite3'

Did I overlook something?

coleifer commented 1 month ago

That indicates that it failed to compile or that it built the extension and put it somewhere else. I'm not sure how you've got your python environment set up so I can't really advise you but likely your compiled extension is in pysqlite3/build/lib.xyz/pysqlite3.

You can try running a find command to locate it if you're having trouble.

strangerinusall commented 1 month ago

So I found it and added to my .zshrc config, and looks like it's there.

❯ find . -name "_sqlite3*.so"
./build/lib.macosx-14.0-arm64-cpython-312/pysqlite3/_sqlite3.cpython-312-darwin.so
❯ python3 -c "import sys; print(sys.path)"
['', '/opt/homebrew/Cellar/python@3.12/3.12.6/Frameworks/Python.framework/Versions/3.12/lib/python312.zip', '/opt/homebrew/Cellar/python@3.12/3.12.6/Frameworks/Python.framework/Versions/3.12/lib/python3.12', '/opt/homebrew/Cellar/python@3.12/3.12.6/Frameworks/Python.framework/Versions/3.12/lib/python3.12/lib-dynload', '/Users/myusername/Library/Python/3.12/lib/python/site-packages', '/opt/homebrew/lib/python3.12/site-packages', '/opt/homebrew/lib/python3.12/site-packages/pysqlite3-0.5.4-py3.12-macosx-14.0-arm64.egg', '/opt/homebrew/opt/python-tk@3.12/libexec']

However from pysqlite3 import dbapi2 as sqlite3 still results in same error.

coleifer commented 1 month ago

I'm not sure you've setup your python path correctly. You would want to add that ./build/lib.macosx-14.0-arm64-cpython-312/ path to it.