program tip

Python : MySQLdb 및 "라이브러리가로드되지 않음 : libmysqlclient.16.dylib"

radiobox 2020. 12. 6. 21:24
반응형

Python : MySQLdb 및 "라이브러리가로드되지 않음 : libmysqlclient.16.dylib"


설정...

python / django를 개발하기 위해 깨끗한 Mac os X 10.6 설치를 설정하려고 시도했지만 10.5에서 실행 한 것을 기억하지 못했습니다.

설치 프로그램에서 MySQL을 설치 한 후 mysql-5.5.8-osx10.6-x86_64.dmg실행

$ sudo pip install MySQL-python

그리고 원활하게 진행되는 것 같았습니다 (아래 출력)

Downloading/unpacking MySQL-python
  Downloading MySQL-python-1.2.3.tar.gz (70Kb): 70Kb downloaded
  Running setup.py egg_info for package MySQL-python
    warning: no files found matching 'MANIFEST'
    warning: no files found matching 'ChangeLog'
    warning: no files found matching 'GPL'
Installing collected packages: MySQL-python
  Running setup.py install for MySQL-python
    building '_mysql' extension
    gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -pipe -Dversion_info=(1,2,3,'final',0) -D__version__=1.2.3 -I/usr/local/mysql/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 -c _mysql.c -o build/temp.macosx-10.6-universal-2.6/_mysql.o -Os -g -fno-common -fno-strict-aliasing -arch x86_64
    In file included from _mysql.c:36:
    /usr/local/mysql/include/my_config.h:325:1: warning: "SIZEOF_SIZE_T" redefined
    In file included from /System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/Python.h:9,
                     from pymemcompat.h:10,
                     from _mysql.c:29:
    /System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/pymacconfig.h:33:1: warning: this is the location of the previous definition
    In file included from _mysql.c:36:
    /usr/local/mysql/include/my_config.h:419:1: warning: "HAVE_WCSCOLL" redefined
    In file included from /System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/Python.h:8,
                     from pymemcompat.h:10,
                     from _mysql.c:29:
    /System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/pyconfig.h:803:1: warning: this is the location of the previous definition
    gcc-4.2 -Wl,-F. -bundle -undefined dynamic_lookup build/temp.macosx-10.6-universal-2.6/_mysql.o -L/usr/local/mysql/lib -lmysqlclient_r -lpthread -o build/lib.macosx-10.6-universal-2.6/_mysql.so -arch x86_64
    warning: no files found matching 'MANIFEST'
    warning: no files found matching 'ChangeLog'
    warning: no files found matching 'GPL'
Successfully installed MySQL-python
Cleaning up...

이 후 나는 시도했다 :

$ python -c "import MySQLdb"

그리고 그것은 나에게 다음과 같이 생겼습니다.

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Library/Python/2.6/site-packages/MySQLdb/__init__.py", line 19, in <module>
    import _mysql
ImportError: dlopen(/Library/Python/2.6/site-packages/_mysql.so, 2): Library not loaded: libmysqlclient.16.dylib
  Referenced from: /Library/Python/2.6/site-packages/_mysql.so
  Reason: image not found

그래서 내 질문에 ...

내가 뭘 잘못 했나요? / 그 밖에 무엇을해야하나요?

이에 대한 인터넷 검색 (및 여기에서 검색)은 Python tho에서는 너무 많지 않은 Ruby에서이 오류 메시지를받는 많은 결과를 반환합니다.


_mysql.so을 나타냅니다 libmysqlclient.16.dylib. 즉, Python과 MySQL 클라이언트 라이브러리 간의 브리지 역할을하는 공유 라이브러리 인은 MySQL 클라이언트 라이브러리 _mysql.so의 동적 라이브러리를 참조하며 어떤 이유로 해당 라이브러리를로드 할 수 없습니다.

답변해야 할 질문 :

  • 거기에 libmysqlclient.16.dylib시스템에 어디는? 그렇지 않은 경우 MySQL 클라이언트 소프트웨어를 설치해야합니다.
  • 그렇다면 해당 라이브러리가 포함 된 디렉토리가 DYLD_LIBRARY_PATH설정에 있습니까? 그렇지 않은 경우 추가해보십시오.
  • 그렇다면 libmysqlclient.16.dylib파일이 손상되지 않았 는지 확인해야합니다 . /opt/local/lib/mysql5/mysql/libmysqlclient.16.dylibMacPorts에 의해에 설치된 내 사본 은 MD5 서명을 c79ee91af08057dfc269ee212915801a가지며 크기는 1,462,376 바이트입니다. 사본은 어떻게 생겼습니까?

DYLD_LIBRARY_PATH실행 후 pip install또는 easy_install다음을 설정하십시오 .

export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/

MySQL 설치가 /usr/local/mysql.


easy_install 후 문제를 해결하는 소프트 링크를 만듭니다.

sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/local/lib/libmysqlclient.18.dylib

It can also crop up if your MySQL client is newer than your MySQL-python package. In my case, I had a libmysqlclient_r.18.dylib on my machine, but not a libmysqlclient_r.16.dylib. Running pip search mysql revealed

MySQL-python - Python interface to MySQL INSTALLED: 1.2.3 LATEST: 1.2.3c1

and running pip install --upgrade MySQL-python fixed my problem.


On the latest version of MySQL 5.7.9 it's no support from MySQL-python and I used the PyMySQL library instead. Also I added in manage.py (in Django project) these lines to emulate API of MySQL-python:

try:
    # load MySQLdb interface emulation
    import pymysql
    pymysql.install_as_MySQLdb()
except ImportError:
    pass

On my setup (mysql 5.7.x from brew, pyenv), I had a newer lib file libmysqlclient.20.dylib. What worked was to pip uninstall MySQL-python and pip install MySQL-python.


For those like me who need - or have - both MySQLdb & PyMySQL installed (in my case, I needed to have both installed because I use PyMySQL to connect to my local MySQL instances, and MySQLDb for remote/live instances):

Be sure you're using the right URI scheme. To access the local instances:

LOCAL_DATABASE_URI = 'mysql+pymysql://username:password@hostname/dbname'

and for live:

REMOTE_DATABASE_URI = 'mysql+mysqldb://username:password@hostname/dbname'

Making this distinction solved the issue for me

참고URL : https://stackoverflow.com/questions/4559699/python-mysqldb-and-library-not-loaded-libmysqlclient-16-dylib

반응형