1
votes

I am using latest version macOS and homebrew, brew doctor find nothing wrong. and I just use brew install python, brew install python@2 to get latest version of python.

When I type python -c "import sqlite3", I get following error messages:

python2.7 -c "import sqlite3"
130 ↵ Traceback (most recent call last): File "", line 1, in File "/usr/local/Cellar/python@2/2.7.15_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sqlite3/init.py", line 24, in from dbapi2 import * File "/usr/local/Cellar/python@2/2.7.15_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sqlite3/dbapi2.py", line 28, in from _sqlite3 import * ImportError: dlopen(/usr/local/Cellar/python@2/2.7.15_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_sqlite3.so, 2): Symbol not found: _sqlite3_enable_load_extension Referenced from: /usr/local/Cellar/python@2/2.7.15_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_sqlite3.so Expected in: /usr/lib/libsqlite3.dylib in /usr/local/Cellar/python@2/2.7.15_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_sqlite3.so

python -c "import sqlite3"
1 ↵ Traceback (most recent call last): File "", line 1, in File "/usr/local/Cellar/python/3.7.2_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/sqlite3/init.py", line 23, in from sqlite3.dbapi2 import * File "/usr/local/Cellar/python/3.7.2_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/sqlite3/dbapi2.py", line 27, in from _sqlite3 import * ImportError: dlopen(/usr/local/Cellar/python/3.7.2_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload/_sqlite3.cpython-37m-darwin.so, 2): Symbol not found: _sqlite3_enable_load_extension Referenced from: /usr/local/Cellar/python/3.7.2_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload/_sqlite3.cpython-37m-darwin.so Expected in: /usr/lib/libsqlite3.dylib in /usr/local/Cellar/python/3.7.2_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload/_sqlite3.cpython-37m-darwin.so

what may cause the problem? I tried to download python source code and compile it, and move the _sqlite3.so or _sqlite3.cpython-37m-darwin.so file into the brew installed folder, and everything works just fine. Could brew just forget something in the formula? What can I do except for compiling .so file from source and manually solve the problem?

1
macOS 10.14.3 (18D42), and brew doctor print "Your system is ready to brew." Everything seems normal.nimbus_debug
I have the same setup (homebrew python & python@2) and I have got import sqlite working on 3 and "No module named sqlite" on 2Benoît P
BTW, when I run "brew test python" I receive no error! but when actually run import sqlite3, it crashes. I believe this hidden test failure cause the problem. Something is wrong in the formula.nimbus_debug

1 Answers

0
votes

I finally find out where the bug hides. All my macOS devices(including 2 Pros and 1 Air) are sharing the same .zshrc file, and for some reason, I add a export DYLD_LIBRARY_PATH="/Users/myname/Library/Developer/Xcode/iOS DeviceSupport/10.0.1 (14A403)/Symbols/usr/lib/:/usr/lib/" which ruins the build of python sqlite shared library file, for sqlite recently add a feature called '_sqlite3_enable_load_extension'.

when I removed the DYLD_LIBRARY_PATH to the outdated dir, and brew reinstall python everything is fine.

By the way, brew config and brew doctor provides no information about DYLD_LIBRARY_PATH. Next time I'll follow the rules and provide these informations. Problem solved!