I have installed MySQLdb on El Capitan using:
brew install mysql
pip install MySQL-python
When I try python -c "import MySQLdb" I get the following error:
File "<string>", line 1, in <module>
File "MySQLdb/__init__.py", line 19, in <module>
import _mysql
ImportError: dlopen(./_mysql.so, 2): Library not loaded: libssl.1.0.0.dylib
Referenced from: /Users/<user>/anaconda/lib/python2.7/site-packages/_mysql.so
Reason: no suitable image found. Did find:
/usr/local/bin/mysql/lib/libssl.1.0.0.dylib: stat() failed with errno=20
Found some related posts but still did not figure out how to fix this. Any help is much appreciated.
EDIT:
If I decide to revert step 1 (brew uninstall mysql) because SQLite (sqlite3) comes pre-installed with El Capitan, I get the following error message:
File "<string>", line 1, in <module>
File "/Users/<user>/anaconda/lib/python2.7/site-packages/MySQLdb/__init__.py", line 19, in <module>
import _mysql
ImportError: dlopen(/Users/<user>/anaconda/lib/python2.7/site-packages/_mysql.so, 2): Library not loaded: /usr/local/opt/mysql/lib/libmysqlclient.20.dylib
Referenced from: /Users/<user>/anaconda/lib/python2.7/site-packages/_mysql.so
Reason: image not found
What am I missing? Are the two error messages related?
I got an error like this after, I assume, homebrew updated mysql. By running pip uninstall mysqlclient && pip install mysqlclient I got things working again without having to set DYLD_LIBRARY_PATH.
Related
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!
Can anyone help me fixing an error when importing opencv in python3?
when I import cv2 in python3, I get something like
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-
packages/cv2/__init__.py", line 4, in <module>
from .cv2 import *
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/cv2/cv2.cpython-36m-darwin.so, 2):
Symbol not found: _clock_gettime
Referenced from: /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/cv2/.dylibs/libavutil.55.78.100.dylib
(which was built for Mac OS X 10.12)
Expected in: /usr/lib/libSystem.B.dylib
in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/cv2/.dylibs/libavutil.55.78.100.dylib
Also, I'm using python version 3.6.3
If you don't want to upgrade your OS, you can install an earlier version of opencv:
pip install opencv-python==3.3.0.10
clock_gettime() was added in macOS 10.12. It says so in the error message.
From what I understand it may be possible to build against an earlier Xcode SDK, but the easiest is probably to upgrade to Mac's latest OS.
I am trying to connect a MySQL database to my Django project, but when I try to install MySQL-python, it gives me the following error:
Collecting mysql-python
Using cached MySQL-python-1.2.5.zip
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/fr/3k1nrq490dzdz9s48k49m9640000gn/T/pip-build-4dsuxwwv/mysql-python/setup.py", line 13, in <module>
from setup_posix import get_config
File "/private/var/folders/fr/3k1nrq490dzdz9s48k49m9640000gn/T/pip-build-4dsuxwwv/mysql-python/setup_posix.py", line 2, in <module>
from ConfigParser import SafeConfigParser
ModuleNotFoundError: No module named 'ConfigParser'
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/fr/3k1nrq490dzdz9s48k49m9640000gn/T/pip-build-4dsuxwwv/mysql-python/
I have tried pip3 install ConfigParser, but while it gets installed, the error still occurs.
When I try to run my Django server, it prints out a long error log, and at the end:
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.
Did you install mysqlclient?
and when I looked at the following link, it said that I should install MySQL-python: Django mysqlclient install
May seem like a newbie question, but I can't seem to find similar errors elsewhere online.
EDIT:: Ok, looks like MySQL-python is not for python-3.6
While I did pip3 install mysqlclient, the virtualenv is saying that I have already installed it when I run the command again. But when I try to python3 manage.py runserver, I get the above error, asking if I had installed it. When I try to give an answer, I am unable to. Everytime I press ENTER, it just creates a new line and the prompt is still active.
The above error is preceded by the following text:
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x1059d9048>
Traceback (most recent call last):
File "/Users/karthikpullela/Desktop/Django-projects/QB-test/QB/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 15, in <module>
import MySQLdb as Database
File "/Users/karthikpullela/Desktop/Django-projects/QB-test/QB/lib/python3.6/site-packages/MySQLdb/__init__.py", line 19, in <module>
import _mysql
ImportError: dlopen(/Users/karthikpullela/Desktop/Django-projects/QB-test/QB/lib/python3.6/site-packages/_mysql.cpython-36m-darwin.so, 2): Library not loaded: libmysqlclient.18.dylib
Referenced from: /Users/karthikpullela/Desktop/Django-projects/QB-test/QB/lib/python3.6/site-packages/_mysql.cpython-36m-darwin.so
Reason: image not found
The above exception was the direct cause of the following exception:
Python 3 does not include ConfigParser
only has configparser
>>> import ConfigParser
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'ConfigParser'
>>> import configparser
Try Python 2.7 which still works if we use import ConfigParser
Try to install with different package, it has support for python 3.
pip install mysqlclient
If there is error while installing in virtualenv, do install this first.
sudo apt-get -y install python3-dev libmysqlclient-dev
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/"
I'm getting a strange error which I can't make sense of.
On Python 2.7, I installed the py27-networkx package using MacPorts. When I try to import networkx as nx, I get the error below. The only line in my network.py file is the import one.
Any ideas on how to debug this to work out what's happening?
Traceback (most recent call last):
File "network.py", line 1, in <module>
import networkx
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/networkx/__init__.py", line 43, in <module>
from networkx import release
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/networkx/release.py", line 45, in <module>
import subprocess
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 427, in <module>
import select
ImportError: dlopen(/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/select.so, 2): Symbol not found: __PyInt_AsInt
Referenced from: /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/select.so
Expected in: flat namespace
in /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/select.so
Update
Ran a few pieces to help diagnose. Hope it helps someone provide some insight and a solution to this for me.
which python gives me /opt/local/bin/python (I have the standard Mac OS X python, but am using a MacPorts installed version of python2.7)
Running import networkx from the python prompt produces no errors
Anything else I can try?
I also had this error and i fixed by upgrading python27 with macports.
Update macports to the latest version:
sudo port selfupdate
List outdated packages (python27 was outdated for me, when I was getting the import error):
sudo port outdated
Update the outdated packages:
sudo port upgrade outdated