2012-11-18 4 views
12

Ecco il mio problema: Non riesco a ottenere MySQLdb per Python funzionante. La maggior parte degli altri post relativi a questo hanno citato diverse architetture di MySQL/Python. Ho controllato e sono entrambi a 64 bit. Ho Python 2.7.2 (OS X standard) e l'ultimo MySQL, OS X 10.8.2.MySQLdb per Python 2.7 su OSX 10.8.2 e BOTH sono 64 bit

miei log di errore originale:

tentando di importare db MySQL mi dà questo errore:

Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    File "/Library/Python/2.7/site-packages/MySQL_python-1.2.4b4-py2.7-macosx-10.8-intel.egg/MySQLdb/__init__.py", line 19, in <module> 
    import _mysql 
ImportError: dlopen(/Library/Python/2.7/site-packages/MySQL_python-1.2.4b4-py2.7-macosx-10.8-intel.egg/_mysql.so, 2): Library not loaded: libmysqlclient.18.dylib 
    Referenced from: /Library/Python/2.7/site-packages/MySQL_python-1.2.4b4-py2.7-macosx-10.8-intel.egg/_mysql.so 
    Reason: image not found 

Questo potrebbe essere utile pure, l'uscita della console, mentre io installare MySQL-python 1.2. 4b4

xxx-MBP:MySQL-python-1.2.4b4 me$ sudo python setup.py clean 
running clean 
removing 'build/temp.macosx-10.8-intel-2.7' (and everything under it) 
xxx-MBP:MySQL-python-1.2.4b4 me$ sudo python setup.py install 
running install 
running bdist_egg 
running egg_info 
writing MySQL_python.egg-info/PKG-INFO 
writing top-level names to MySQL_python.egg-info/top_level.txt 
writing dependency_links to MySQL_python.egg-info/dependency_links.txt 
writing MySQL_python.egg-info/PKG-INFO 
writing top-level names to MySQL_python.egg-info/top_level.txt 
writing dependency_links to MySQL_python.egg-info/dependency_links.txt 
reading manifest file 'MySQL_python.egg-info/SOURCES.txt' 
reading manifest template 'MANIFEST.in' 
writing manifest file 'MySQL_python.egg-info/SOURCES.txt' 
installing library code to build/bdist.macosx-10.8-intel/egg 
running install_lib 
running build_py 
copying MySQLdb/release.py -> build/lib.macosx-10.8-intel-2.7/MySQLdb 
running build_ext 
creating build/bdist.macosx-10.8-intel/egg 
copying build/lib.macosx-10.8-intel-2.7/_mysql.so -> build/bdist.macosx-10.8-intel/egg 
copying build/lib.macosx-10.8-intel-2.7/_mysql_exceptions.py -> build/bdist.macosx-10.8-intel/egg 
creating build/bdist.macosx-10.8-intel/egg/MySQLdb 
copying build/lib.macosx-10.8-intel-2.7/MySQLdb/__init__.py -> build/bdist.macosx-10.8-intel/egg/MySQLdb 
copying build/lib.macosx-10.8-intel-2.7/MySQLdb/connections.py -> build/bdist.macosx-10.8-intel/egg/MySQLdb 
creating build/bdist.macosx-10.8-intel/egg/MySQLdb/constants 
copying build/lib.macosx-10.8-intel-2.7/MySQLdb/constants/__init__.py -> build/bdist.macosx-10.8-intel/egg/MySQLdb/constants 
copying build/lib.macosx-10.8-intel-2.7/MySQLdb/constants/CLIENT.py -> build/bdist.macosx-10.8-intel/egg/MySQLdb/constants 
copying build/lib.macosx-10.8-intel-2.7/MySQLdb/constants/CR.py -> build/bdist.macosx-10.8-intel/egg/MySQLdb/constants 
copying build/lib.macosx-10.8-intel-2.7/MySQLdb/constants/ER.py -> build/bdist.macosx-10.8-intel/egg/MySQLdb/constants 
copying build/lib.macosx-10.8-intel-2.7/MySQLdb/constants/FIELD_TYPE.py -> build/bdist.macosx-10.8-intel/egg/MySQLdb/constants 
copying build/lib.macosx-10.8-intel-2.7/MySQLdb/constants/FLAG.py -> build/bdist.macosx-10.8-intel/egg/MySQLdb/constants 
copying build/lib.macosx-10.8-intel-2.7/MySQLdb/constants/REFRESH.py -> build/bdist.macosx-10.8-intel/egg/MySQLdb/constants 
copying build/lib.macosx-10.8-intel-2.7/MySQLdb/converters.py -> build/bdist.macosx-10.8-intel/egg/MySQLdb 
copying build/lib.macosx-10.8-intel-2.7/MySQLdb/cursors.py -> build/bdist.macosx-10.8-intel/egg/MySQLdb 
copying build/lib.macosx-10.8-intel-2.7/MySQLdb/release.py -> build/bdist.macosx-10.8-intel/egg/MySQLdb 
copying build/lib.macosx-10.8-intel-2.7/MySQLdb/times.py -> build/bdist.macosx-10.8-intel/egg/MySQLdb 
byte-compiling build/bdist.macosx-10.8-intel/egg/_mysql_exceptions.py to _mysql_exceptions.pyc 
byte-compiling build/bdist.macosx-10.8-intel/egg/MySQLdb/__init__.py to __init__.pyc 
byte-compiling build/bdist.macosx-10.8-intel/egg/MySQLdb/connections.py to connections.pyc 
byte-compiling build/bdist.macosx-10.8-intel/egg/MySQLdb/constants/__init__.py to __init__.pyc 
byte-compiling build/bdist.macosx-10.8-intel/egg/MySQLdb/constants/CLIENT.py to CLIENT.pyc 
byte-compiling build/bdist.macosx-10.8-intel/egg/MySQLdb/constants/CR.py to CR.pyc 
byte-compiling build/bdist.macosx-10.8-intel/egg/MySQLdb/constants/ER.py to ER.pyc 
byte-compiling build/bdist.macosx-10.8-intel/egg/MySQLdb/constants/FIELD_TYPE.py to FIELD_TYPE.pyc 
byte-compiling build/bdist.macosx-10.8-intel/egg/MySQLdb/constants/FLAG.py to FLAG.pyc 
byte-compiling build/bdist.macosx-10.8-intel/egg/MySQLdb/constants/REFRESH.py to REFRESH.pyc 
byte-compiling build/bdist.macosx-10.8-intel/egg/MySQLdb/converters.py to converters.pyc 
byte-compiling build/bdist.macosx-10.8-intel/egg/MySQLdb/cursors.py to cursors.pyc 
byte-compiling build/bdist.macosx-10.8-intel/egg/MySQLdb/release.py to release.pyc 
byte-compiling build/bdist.macosx-10.8-intel/egg/MySQLdb/times.py to times.pyc 
creating stub loader for _mysql.so 
byte-compiling build/bdist.macosx-10.8-intel/egg/_mysql.py to _mysql.pyc 
creating build/bdist.macosx-10.8-intel/egg/EGG-INFO 
copying MySQL_python.egg-info/PKG-INFO -> build/bdist.macosx-10.8-intel/egg/EGG-INFO 
copying MySQL_python.egg-info/SOURCES.txt -> build/bdist.macosx-10.8-intel/egg/EGG-INFO 
copying MySQL_python.egg-info/dependency_links.txt -> build/bdist.macosx-10.8-intel/egg/EGG-INFO 
copying MySQL_python.egg-info/top_level.txt -> build/bdist.macosx-10.8-intel/egg/EGG-INFO 
writing build/bdist.macosx-10.8-intel/egg/EGG-INFO/native_libs.txt 
zip_safe flag not set; analyzing archive contents... 
creating 'dist/MySQL_python-1.2.4b4-py2.7-macosx-10.8-intel.egg' and adding 'build/bdist.macosx-10.8-intel/egg' to it 
removing 'build/bdist.macosx-10.8-intel/egg' (and everything under it) 
Processing MySQL_python-1.2.4b4-py2.7-macosx-10.8-intel.egg 
removing '/Library/Python/2.7/site-packages/MySQL_python-1.2.4b4-py2.7-macosx-10.8-intel.egg' (and everything under it) 
creating /Library/Python/2.7/site-packages/MySQL_python-1.2.4b4-py2.7-macosx-10.8-intel.egg 
Extracting MySQL_python-1.2.4b4-py2.7-macosx-10.8-intel.egg to /Library/Python/2.7/site-packages 
MySQL-python 1.2.4b4 is already the active version in easy-install.pth 

Installed /Library/Python/2.7/site-packages/MySQL_python-1.2.4b4-py2.7-macosx-10.8-intel.egg 
Processing dependencies for MySQL-python==1.2.4b4 
Finished processing dependencies for MySQL-python==1.2.4b4 
+0

Nota interessante, ho pulito la mia installazione e ho seguito questi (http://birdhouse.org/blog/2009/02/21/python-mysql-connections-on-mac-os /) indicazioni (la parte macports non ha funzionato per me), in particolare ho ricostruito utilizzando i flag a 64 bit durante il processo di compilazione e quindi reinstallato. ORA QUALCOSA DI SUCCESSI A WIERD. Importa MySQLdb FUNZIONA DAL TERMINALE, ma NON dall'interno di un editor di codice. – Tizzee

+0

Anche di Note,/library/python contiene cartelle per 2.3, 2.4, 2.5, 2.6 e 2.7, ma il 2.7 ha roba in esso. WITHIN 2.7 (/library/python/2.7/) Ho un file egg multipli, un MySQL_python-1.2.4b4-py2.7-macosx-10.8-intel.egg, AND un MySQL_python-1.2.4b4-py2.7-macosx -10.8-x86_64.egg, ed entrambi hanno gli stessi file al loro interno ... dovrei eliminarne uno? quale dovrei mantenere? Sono così estremamente frustrato ragazzi. – Tizzee

+0

ANCHE NOTA: se controllo, comando | | mentre in Python nel terminale, esce, ma ottengo una finestra OSX che dice che Python si chiude in modo imprevisto. – Tizzee

risposta

13

I THINK I GOT IT! Ecco cosa ho fatto.

OK, questo è stato estremamente frustrante.

Che fine ha fatto il lavoro stava facendo questo nel terminale:

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

Ma c'era un sacco di altre cose prima. Ho mescolato le direzioni da due fonti:

How to install MySQLdb (Python data access library to MySQL) on Mac OS X? e http://birdhouse.org/blog/2009/02/21/python-mysql-connections-on-mac-os/

ho usato la prima per pulire pitone e modificare i file di generazione ... ho usato il secondo per aggiungere 64 flag di bit per l'installazione e costruire ...

Poi ho usato una risposta a Error importing MySQLdb in Python 2.7.2 on Mac OSx 10.8.1 (che era l'ultima cosa che ha reso il lavoro.)

per impostare me oltre il bordo.

Non sono sicuro di cosa abbia fatto la differenza perché ho fatto COSE MOLTE COSE. Ho cancellato un sacco di cose dalla cartella python 2.7 ... e altre cose. Ma l'unica cosa di cui posso essere certo è che mescolare le direzioni di quelle due fonti ha fatto la differenza. Grazie per tutto l'aiuto, ragazzi ... .lol spero che questo salvi qualcuno mal di testa.

0

Ho elencato i 4 impedimenti di configurazione che ho affrontato, li ho elencati.

export CFLAGS = -Qunused-argomenti export CPPFLAGS = -Qunused-argomenti installazione di strumenti a linea di comando di preferenze Xcode/downloads sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib/usr /lib/libmysqlclient.18.dylib