When installing mysql, I have been active for two days. I finally succeeded in the fight ......
At first I put a mistake: I got a 32-bit mysql: mysql-5.5.8-osx10.6-x86.dmg
Note that 64-bit python is installed on mac. Therefore, an error occurred while installing mysql's python driver Mysql-python:
ImportError dlopen (.... /.... /_ Mysql. so, 2)
Note: When installing mysql-python, the error mysql_config cannot be found. You can modify the installation file as instructed on the Internet, the best way is to add the bin folder of mysql to the environment variable.
And so on ...... It is very similar to the error mentioned below. I don't know if it is the same. The window is closed and cannot be tested ...... The official faq.txt mentioned this error, saying that the gcc version is different and may be old. Later, I checked some web pages and learned that mac was originally using 64-bit python, so I used 64-bit mysql ......
So uninstall it. The result shows that the mysql dmg package has not been uninstalled ...... Depressed, I found the method for uninstalling mysql on the Internet. I had to manually delete it.
The methods described in many articles on the Internet are not clean and lost. I found it on stackflow and wrote it for your reference. Http://hearrain.com/2011/01/495
After changing the 64-bit installation package, there should be no problem. The result still shows such a similar error.
So we simply switched to homebrew for installation.
As a result, the mysql installed in homebrew has no import problem in python, but the database cannot be initialized ...... I asked on homebrew's official website, but I have never been able to solve it ...... (I really don't know if it's my character problem)
Homebrew mysql is the classic version of The mysql-5.1.54, I suspect that the version of the problem, just turn to the official website under the mysql-5.1.54 Binary Package
The result database can be initialized, but the following error occurs when importing MySQLdb in python.
>>> import MySQLdb
Traceback (most recent call last):
File "", line 1, in
File "MySQLdb/__init__.py", line 19, in
import _mysql
ImportError: dlopen(/usr/local/Cellar/python/2.7.1/lib/python2.7/site-packages/MySQL_python-1.2.3-py2.7-macosx-10.4-x86_64.egg/_mysql.so, 2): Library not loaded: /usr/local/Cellar/mysql/5.1.54/lib/mysql/libmysqlclient_r.16.dylib
Referenced from: /usr/local/Cellar/python/2.7.1/lib/python2.7/site-packages/MySQL_python-1.2.3-py2.7-macosx-10.4-x86_64.egg/_mysql.so
Reason: image not found
I think I should study the error code.
The error indicates that libmysqlclient_r.16.dylib cannot be loaded, but libmysqlclient_r.16.dylib is in mysql lib.
The result mentioned in stackoverflow the File validation libmysqlclient_r.16.dylib, so I have fixed the problem.
However, I found the real cause of the problem in this article (this article should also be on stackoverflow): the mysql-python build problem.
In this article, we carefully checked libmysqlclient_r.16.dylib and _ mysql. so in python2.7/site-packages in mysql/lib.
Otool-L _ mysql. so analysis shows that the original _ mysql. so link is still the location of libmysqlclient_r.16.dylib when homebrew installed mysql ...... Because mysql-python is built during install, the old location is retained, so you need to build it again. It is best to delete it and decompress it for installation.
So I think the reason why the import fails in python when the previous 64-bit is installed is that mysql-python retains the old location during the install process ...... Ah ...... No culture is really killing people.
Decompress mysql-python and install again. The test is successful.
Summary:
1. The pre-installed python in mac is 64-bit, so you must use 64-bit mysql. Installation: http://hearrain.com/2011/01/498
2. It is troublesome to uninstall mysql in DMG format on mac. Unload method: http://hearrain.com/2011/01/495
3. After installing mysql or other software, remember to set environment variables. The method http://hearrain.com/2011/01/490 for modifying environment variables in mac is mentioned.
4. When using setuptools to reinstall the python component, remember to build it again or decompress it again.
5. Analyze the error code carefully, track the error source, and be good at finding answers on stackoverflow. Stackoverflow is a really awesome technical Q & A community. Communities like quora are a bit messy. The technology community should be very vertical. It is very simple. The social elements of Shenma are full of clouds.
This article from: http://hearrain.com/2011/01/494