這篇文章主要跟大家介紹了在linux環境下python中MySQLdb模組的安裝方法,文中跟大家介紹的非常詳細,對大家的學習或工作有一定的參考學習價值,需要的朋友們下面來一起看看吧。
前言
最近開始學習python資料庫程式設計後,在了解了基本概念,打算上手試驗一下時,卡在了MYSQLdb包的安裝上,折騰了半天才解決。記錄一下我在linux中安裝此套件遇到的問題。
系統是ubuntn15.04。
1.下載
第一個問題是pycharm軟體的模組安裝功能Project Interpreter無法自動下載安裝MYSQLdb包,顯示
Error occurred when installling package
那沒辦法了,只好手動下載了。 MYSQLdb包linux系統的下載的位址是:http://sourceforge.net/projects/mysql-python/file/mysql-python/
在頁面內選擇你想要安裝的版本下載即可,我下載的版本是1.2.4b4
2.安裝
一:下載之後,開啟終端,切換到自己的下載文件目錄,在我的電腦上是目錄/home/hai/download,之後解壓縮下載的文件,即在終端輸入:
##
tar xfz MySQL-python-1.2.4b4.tar.gz
二:使用指令
cd MySQL-python-1.2.4b4切換到解壓縮後的目錄。
三:編譯MYSQLdb套件
輸入指令python setup.py build此時遇到問題,報錯訊息是
mysql_config not foundgoogle之後發現要修改MYSQLdb解壓縮之後目錄中的setup_posix.py第26行,此行的內容是
#
mysql_config.path = "mysql_config"mysql_config是mysql安裝目錄中的一個檔案的名稱,需要將26行變數的值改為為此檔案的絕對路徑。 於是使用
whereis mysql檢視資料庫安裝目錄,進入安裝目錄。但是發現安裝目錄中並沒有mysql_config文件,啊,好氣啊。 再繼續google,發現是沒有安裝libmysqlclient-dev,那就安裝吧!使用指令:
sudo apt-get install libmysqlclient-dev安裝這個東西,之後使用指令:
file -name mysql_config檢視這個檔案的路徑,ok ,有了。 將setup_posix.py檔案修改後,再使用python setup-python-1.2.4b4安裝,又遇到問題了,
錯誤訊息:
#
error: command 'i686-linux-gnu-gcc' failed with exit status 1啊啊啊。 繼續google,原來是沒有安裝python-dev,好的,那就安裝.使用指令:
sudo apt-get install python-dev安裝完成後,再使用輸入了N次的命令
python setup.py build,好,終於沒有報錯了,現在就差一步就安裝成功了。
四:輸入指令sudo python setup.py install
#好,終於安裝上了,在python中實驗一下,導入一下MYSQLdb模組,import MYSQLdb,沒有消息,恩,沒有訊息就是最好的消息,安裝成功!
P.S
另外在google過程中,我看到了好幾個錯誤警報,雖然我沒有遇到,還是在這裡提一下。- 第一個是如果沒有安裝steuptools,在第三步驟編譯時會報錯
ImportError: No
module<a href="http://www.php.cn/code/8212.html" target="_blank"> named setuptools</a> ,那就去安裝setuptools,至於setuptools的安裝,那就是另外的問題了,就不多說了。
- 第二個是關於python.h檔案報錯,這是python版本的問題,需要處理一下python版本,也不再多說。
- 第三個是/usr/bin/ld:cannot find -lmysqlclient_r報錯,這是由於
設定檔沒有生效。找到mysql的設定文件,使用使用:ldconfig
命令刷新使其生效即可。
總結#
以上是python中MySQLdb模組在linux環境下的安裝方法介紹的詳細內容。更多資訊請關注PHP中文網其他相關文章!

pythonlistscanStoryDatatepe,ArrayModulearRaysStoreOneType,and numpyArraySareSareAraysareSareAraysareSareComputations.1)列出sareversArversAtileButlessMemory-Felide.2)arraymoduleareareMogeMogeNareSaremogeNormogeNoreSoustAta.3)

WhenyouattempttostoreavalueofthewrongdatatypeinaPythonarray,you'llencounteraTypeError.Thisisduetothearraymodule'sstricttypeenforcement,whichrequiresallelementstobeofthesametypeasspecifiedbythetypecode.Forperformancereasons,arraysaremoreefficientthanl

pythonlistsarepartofthestAndArdLibrary,herilearRaysarenot.listsarebuilt-In,多功能,和Rused ForStoringCollections,而EasaraySaraySaraySaraysaraySaraySaraysaraySaraysarrayModuleandleandleandlesscommonlyusedDduetolimitedFunctionalityFunctionalityFunctionality。

ThescriptisrunningwiththewrongPythonversionduetoincorrectdefaultinterpretersettings.Tofixthis:1)CheckthedefaultPythonversionusingpython--versionorpython3--version.2)Usevirtualenvironmentsbycreatingonewithpython3.9-mvenvmyenv,activatingit,andverifying

Pythonarrayssupportvariousoperations:1)Slicingextractssubsets,2)Appending/Extendingaddselements,3)Insertingplaceselementsatspecificpositions,4)Removingdeleteselements,5)Sorting/Reversingchangesorder,and6)Listcomprehensionscreatenewlistsbasedonexistin

NumPyarraysareessentialforapplicationsrequiringefficientnumericalcomputationsanddatamanipulation.Theyarecrucialindatascience,machinelearning,physics,engineering,andfinanceduetotheirabilitytohandlelarge-scaledataefficiently.Forexample,infinancialanaly

useanArray.ArarayoveralistinpythonwhendeAlingwithHomoGeneData,performance-Caliticalcode,orinterfacingwithccode.1)同質性data:arraysSaveMemorywithTypedElements.2)績效code-performance-calitialcode-calliginal-clitical-clitical-calligation-Critical-Code:Arraysofferferbetterperbetterperperformanceformanceformancefornallancefornalumericalical.3)

不,notalllistoperationsareSupportedByArrays,andviceversa.1)arraysdonotsupportdynamicoperationslikeappendorinsertwithoutresizing,wheremactsperformance.2)listssdonotguaranteeconecontanttanttanttanttanttanttanttanttanttimecomplecomecomplecomecomecomecomecomecomplecomectacccesslectaccesslecrectaccesslerikearraysodo。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

禪工作室 13.0.1
強大的PHP整合開發環境

Atom編輯器mac版下載
最受歡迎的的開源編輯器

Dreamweaver CS6
視覺化網頁開發工具

WebStorm Mac版
好用的JavaScript開發工具

DVWA
Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中