1

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?

3
  • macOS 10.14.3 (18D42), and brew doctor print "Your system is ready to brew." Everything seems normal. Commented Feb 1, 2019 at 8:57
  • I have the same setup (homebrew python & python@2) and I have got import sqlite working on 3 and "No module named sqlite" on 2 Commented Feb 1, 2019 at 9:17
  • 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. Commented Feb 1, 2019 at 9:18

1 Answer 1

0

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!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.