python中最連線mysql常用的驅動是
mysql-python :mysql的c語言的驅動
mysql-connector:msql官方的驅動
pymysql:python語言的驅動
我這裡安裝的是 mysql-python
終端中執行
pip install mysql-python
運氣好的的話,直接就成功了,我遇到了一下問題,最終找到了解決方案,原因及解決方案如下,供參考
終端列印出:
collecting mysql-python
downloading mysql-python-1.2.5.zip (108kb)
100% |████████████████████████████████| 110kb 30kb/s
complete output from command python setup.py egg_info:
sh: mysql_config: command not found
traceback (most recent call last):
file "", line 20, in file "/private/tmp/pip-build-np8j3v/mysql-python/ setup.py", line 17, in metadata, options = get_config()
file "setup_posix.py", line 43, in get_config
libs = mysql_config("libs_r")
file "setup_posix.py", line 25, in mysql_config
raise environmenterror("%s not found" % (mysql_config.path,))
environmenterror: mysql_config not found
----------------------------------------
command "python setup.py egg_info" failed with error code 1 in /private/tmp/pip-build-np8j3v/mysql-python
解決方法,執行:
ln -s /usr/local/mysql/bin/mysql_config /usr/local/bin/mysql_config
原因
找不到mysql_config一般是由於通過lnmp.org或者其他方式安裝mysql以後mysql_config是在/usr/local/mysql/bin/裡面,這裡面的檔案不是在任意位置都可以訪問的,而指令是
將mysql_config鏈結到/usr/local/bin目錄下
參考一條命令解決mysql_config not found
出錯資訊為:
traceback (most recent call last):
file "manage.py", line 4, in from models import user
file "/users/tengfei/pycharmprojects/mysql/models.py", line 1, in import mysqldb
file "/library/python/2.7/site-packages/mysqldb/__init__.py", line 19, in import _mysql
importerror: dlopen(/library/python/2.7/site-packages/_mysql.so, 2): library not loaded: libmysqlclient.18.dylib
referenced from: /library/python/2.7/site-packages/_mysql.so
reason: image not found
解決:
pip install --upgrade pip
修改 os x 環境變數:開啟終端,在終端中使用 vim 開啟 「~/.bash_profile」,如果沒有安裝 vim,那就顯示隱藏檔案用文字編輯器開啟,具體操作這裡就不複述了。在 .bash_profile 中新增以下內容
path="/usr/local/mysql/bin:$"
export path
export dyld_library_path=/usr/local/mysql/lib/
export versioner_python_prefer_64_bit=no
export versioner_python_prefer_32_bit=yes
其中 versioner_python_prefer_64_bit 和 versioner_python_prefer_64_bit 根據自己安裝的 mysql 進行選擇。
參考:mysqldb(即 mysql-python 包)在 os x 中安裝指南
solving library not loaded: libmysqlclient.18.dylib when importing mysqldb on lion
mac os + mysql-python-1.2.3: importerror | library not loaded | libmysqlclient.16.dylib
執行pip install mysql-python後的出錯資訊如下:
這是在虛擬環境中見到的
^compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
----------------------------------------
command "/home/tengfei/api01/test/testto/todo-orm/venv/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-w6mp1w/mysql-python/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-jg7ekf-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/tengfei/api01/test/testto/todo-orm/venv/include/site/python2.7/mysql-python" failed with error code 1 in /tmp/pip-build-w6mp1w/mysql-python/
原因是:一些依賴包沒有安裝,注意這也是很多實用pip執行安裝擴充套件的時候,常見的錯誤
apt-get build-dep python-lxml
sudo pip install lxml --upgrade
pip install mysql-python
參考:[ubuntu/pip] 解決 pip 安裝 lxml 出現 x86_64-linux-gnu-gcc 異常 Python下安裝MySQL驅動出錯
python中安裝mysql時 pip install mysql connector 出現下面的報錯 unable to find protobuf include directory.command d python python.exe u c import setuptools,tokeni...
安裝python的mysql驅動的問題
在fedora 15下安裝python的mysql驅動遇到了兩個小問題,記錄一下 1 找不到setuptools模組 在執行python setup.py build時提示找不到setuptools模組。img 解決 安裝setuptools模組即可。2 build過程中提示找不到python.h檔...
Phyton安裝MySQL驅動
使用python的時候,有時候會使用到mysql,自然也會使用到資料庫的驅動。你可以採取如下命令 pip install mysql connector python allow external mysql connector python 來進行安裝驅動。但是有時候可能會出現如下的錯誤 原因有兩...