国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

在MAC下Python+Django+mysql配置

2019-11-14 17:32:04
字體:
來源:轉載
供稿:網友

今天在搭建Django+MySQL環境的時候遇到了一點問題,記錄下來。

 

安裝環境:OS X 10.10操作系統,Python 2.7。

MySQLdb其實包含在MySQL-python包中,因此無論下載還是在pip中search,都應該是搜尋MySQL-python。

 

以下將說明MySQLdb兩種常見的安裝方式:

下載安裝或者pip安裝MySQL-python。 

源碼安裝

下載MySQLdb源碼

下面是1.2.5的版本

https://pypi.python.org/packages/source/M/MySQL-python/MySQL-python-1.2.5.zip

下載后解壓,然后在終端Terminal中執行以下命令:

cd MySQL-python-1.2.5

 然后修改 site.cfg, 修改下面內容:

由#mysql_config = /usr/local/bin/mysql_config

改成mysql_config = /usr/local/mysql/bin/mysql_config

否則會出現找不到 MySQL config 的問題:

File "/tmp/easy_install-nHSsgl/MySQL-python-1.2.2/setup_posix.py", line 24, in mysql_config
EnvironmentError: mysql_config not found

然后修改 _mysql.c, 把第 37 到 39 行注釋掉, 如下:

//#ifndef uint//#define uint unsigned int//#endif


否則會出現:

In file included from /usr/local/mysql/include/mysql.h:47,                 from _mysql.c:40:/usr/include/sys/types.h:92: error: duplicate 'unsigned'/usr/include/sys/types.h:92: error: two or more data types in declaration specifierserror: command 'gcc' failed with exit status 1

然后再用 python ./setup.py build 編譯

$ python ./setup.py build

然后再用 python ./setup.py install 安裝

$ sudo python ./setup.py installPassWord:

使用pip安裝MySQLdb

在終端中執行:$ pip install MySQL-python

使用pip安裝時沒有辦法修改site.cfg文件,因此可以通過修改OS X的系統環境變量來解決找不到mysql_config的錯誤。

修改OS X環境變量:打開終端,在終端中使用vim打開“~/.bash_PRofile”,如果沒有安裝vim,那就顯示隱藏文件用文本編輯器打開,具體操作這里就不復述了。在.bash_profile中添加以下內容:

PATH="/usr/local/mysql/bin:${PATH}"

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進行選擇。

另外再提供一個pip安裝時找不到mysql_config的解決方法,在終端中輸入以下命令:

$ sudo ln -s /usr/local/mysql/bin/* /usr/bin

到這里,MySQL-python包應該基本順利安裝。

 

解決 Reason: image not found 錯誤

安裝完MySQL-python包后,讓我們import MySQLdb,此時出現一個錯誤,錯誤最后一行寫著 Reason: image not found。

解決方法是在終端執行:

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

$ sudo ln -s /usr/local/mysql/lib /usr/local/mysql/lib/mysql

測試

用下面的命令進行測試:

$ cd ~$ pythonPython 2.5.1 (r251:54863, Apr 15 2008, 22:57:26) [GCC 4.0.1 (Apple Inc. build 5465)] on darwinType "help", "copyright", "credits" or "license" for more information.>>> import MySQLdb>>> MySQLdb.apilevel'2.0'>>> import django>>> print django.VERSION(1, 0, 'final') 

常見錯誤

clang: error: unknown argument: '-mno-fused-madd' [-Wunused-command-line-argument-hard-error-in-future]

clang: note: this will be a hard error (cannot be downgraded to a warning) in the future

經網上查證:http://www.tuicool.com/articles/zI7Vzu貌似是mac os的Xcode從5.1起給編譯器規定對于未知參數傳入視為error我們需要使用ARCHFLAGS將該error降級為warning因此最后的安裝命令應該如下:

 

sudo ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future python setup.py build


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 府谷县| 惠水县| 鹤峰县| 台南县| 绵阳市| 乳源| 凤山县| 天等县| 岚皋县| 江陵县| 沧源| 莎车县| 岳普湖县| 安远县| 肇源县| 萍乡市| 彰化市| 沙湾县| 昌宁县| 新化县| 湖州市| 游戏| 大竹县| 双辽市| 榕江县| 万荣县| 始兴县| 工布江达县| 双牌县| 历史| 壶关县| 沙河市| 台中市| 鹿泉市| 阳城县| 上虞市| 琼海市| 华蓥市| 寿阳县| 城固县| 深水埗区|