homebrew python#2 and python provides broken sqlite3 - python

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?

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!

Related

ImportError: dlopen(/usr/local/opt/opencv3/lib/python2.7/site-packages/cv2.so, 2): Symbol not found: _PyCObject_Type

This is how I installed opencv3 on my machine.
I had python 3.6 installed in my system. I ran,
$ brew install opencv3 --with-contrib --with-python3 --HEAD
Then changed the name of opencv3 package in the 3.6 site package.
$ cd /usr/local/opt/opencv3/lib/python3.6/site-packages/
$ mv cv2.cpython-35m-darwin.so cv2.so
And then created .pth file.
$ echo /usr/local/opt/opencv3/lib/python3.6/site-packages >> /usr/local/lib/python3.6/site-packages/opencv3.pth
Now when I get on the python 3 REPL and call
import cv2
This is the error that I get.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dlopen(/usr/local/opt/opencv3/lib/python2.7/site-packages/cv2.so, 2): Symbol not found: _PyCObject_Type
Referenced from: /usr/local/opt/opencv3/lib/python2.7/site-packages/cv2.so
Expected in: flat namespace
in /usr/local/opt/opencv3/lib/python2.7/site-packages/cv2.so
I want my python 3 interpreter to look into the python 3.6 site packages for cv2 and I can't get it to do that. Any help appreciated.
I removed all opencv3 folders and removed the opencv package in python environment and then installed opencv again. It's working for me now.

Python Basemap/Matplotlib Install

I am trying to install the base map for use with matplotlib python v2.7 running on Mac OSX Mavericks. I have all the latest versions of all modules (matplotlib, etc) running using anaconda, but keep getting the following error:
Traceback (most recent call last):
File "simpletest.py", line 1, in <module>
from mpl_toolkits.basemap import Basemap
File "/Users/felishalawrence/anaconda/lib/python2.7/site-packages/mpl_toolkits/basemap/__init__.py", line 37, in <module>
import _geoslib.so
ImportError: dlopen(/Users/felishalawrence/anaconda/lib/python2.7/site-packages/_geoslib.so, 2): Library not loaded: libgeos_c.1.dylib
Referenced from: /Users/felishalawrence/anaconda/lib/python2.7/site-packages/_geoslib.so
Reason: no suitable image found. Did find:
/usr/local/bin/gcc-4.9/libgeos_c.1.dylib: stat() failed with errno=20
Can someone please give me an idea of what is wrong? Thanks!
Try installing the following packages with Homebrew:
brew install numpy
brew install proj
brew install geos
export GEOS_DIR="/usr/local/Cellar/geos/3.10.3/"

Python (homebrew) returns error on Sqlite

I have Python 2.7.6 and Python 3.3.4 installed through homebrew. I ran into some errors when trying to use Sqlite and I traced the error to a "symbol not found" error. Please see the trace below.
How can I get this thing to work?
>>> import sqlite3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sqlite3/__init__.py", line 24, in <module>
from dbapi2 import *
File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sqlite3/dbapi2.py", line 27, in <module>
from _sqlite3 import *
ImportError: dlopen(/usr/local/Cellar/python/2.7.6/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.7.6/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.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_sqlite3.so
edit: Sqlite3 also seems to be properly installed (sqlite-3.8.3 already installed).
On a sidenote, why does homebrew stick with Python 2.7.6 while the Python website offers version 2.7.8 for download?
You need to run brew update; both the sqlite formula and the python formula have seen numerous updates.
Python 2.7.8 has been available since July 2nd, for example. Your SQLite problems have probably long been solved with updates as well.
It is always a good idea to run brew doctor when you are having problems with Homebrew-supplied software; the output would have told you to run brew update too:
$ brew doctor
Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry and just ignore them. Thanks!
Warning: Your Homebrew is outdated.
You haven't updated for at least 24 hours. This is a long time in brewland!
To update Homebrew, run `brew update`.

Cannot get mapnik working with python3, but it does with python2

Here is a post about installing a module in python3. When I use brew install python, then it installs it for 2.7.
When I use the method suggested by dan, which aimed to install it directly in python3 (who i really thank), but which didn't work :
# Figure out the path to python3
PY3DIR=`dirname $(which python3)`
# And /then/ install with brew. That will have it use python3 to get its path
PATH=$PY3DIR:$PATH brew install mapnik
The installation was successful but in python2. so I get:
For non-homebrew Python, you need to amend your PYTHONPATH like so: export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH
so i finally add the path manually in python3 :
import sys
sys.path.append('/usr/local/lib/python2.7/site-packages')
I get this error :
Traceback (most recent call last): File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/mapnik/__init__.py", line 69, in <module>
from _mapnik import * ImportError: dlopen(./_mapnik.so, 2): Symbol not found: _PyClass_Type Referenced from: ./_mapnik.so
Expected in: flat namespace in ./_mapnik.so
Please help, I have spent so many hours on this ...
Thanks!!!
The Mapnik python bindings depend on boost_python. And both need to use the same python. The problem is likely that homebrew is providing a bottle of boost which includes boost python built against python 2.7 and not python 3.x.

psycopg installation problem

I've recently installed django and psycop2. However python is refusing to use it below is the error. Can someone please help?
>>> import psycopg2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/psycopg2/__init__.py", line 67, in <module>
from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/psycopg2/_psycopg.so, 2): Symbol not found: _PQbackendPID
Referenced from: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/psycopg2/_psycopg.so
Expected in: flat namespace
in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/psycopg2/_psycopg.so
macports is terrible for python/django development, everything seems to be out of data.
I have my team doing the following for postgres:
Download and install postgresql 9.0 but read the README before
installing !!!
Download psycopg2 source from http://initd.org/pub/software/psycopg/
Edit the setup.cfg to set pg_config to
/Library/PostgreSQL/9.0/bin/pg_config
Then install with
python setup.py install
I'd recommend using virtualenv as well, you want to stay away from the base Mac OS X python install as much as possible.

Categories