摘要:為位的安裝原文在此基督尼瑪個耶穌這一切始于一個簡單的想法我想裝然后寫個網站并用這個機會多學點和的知識我理所當然的選當數據庫因為在我家里的那臺電腦上裝著之前的一個項目里用到的服務我從沒想到因為選擇讓我接下來的幾個夜晚都因為處理的問題而過的
Install 64-bit MySQLdb for Python 3 on Windows 7 為64位Windows7的Pyhton3安裝MySQLdb
原文在此
Jesus Rollerblading Christ. It all started as a simple idea: I would install Django and start working on this web app idea I had and use it as a chance to learn more about Python and Django. I also decided to go with MySQL as the database for it since I already have a MySQL server installed on my home computer from previous projects. Little did I know that since I had chosen to go with Python 3, I was in for several evenings of pain and agony dealing with MySQLdb. After an emotional rollercoaster of build path fuckery that made me want to claw my eyes out, I finally got it working: I can use MySQLdb for Python 3.2 on Windows 7 64-bit. Here’s my tale in case you find yourself in the same situation and begin to ask yourself, “Why the fuck do people put up with this?”
基督尼瑪個耶穌.這一切始于一個簡單的想法:我想裝Django然后寫個網站,并用這個機會多學點Python和Djiango的知識.我理所當然的選MySQL當數據庫,因為在我家里的那臺電腦上裝著之前的一個項目里用到的MySQL服務.我從沒想到因為選擇Python3,讓我接下來的幾個夜晚都因為處理MySQLdb的問題而過的痛苦.之后的沒用的構建路徑讓我情緒很不穩定,都想抓出自己的眼睛.最后總算是搞定了:我可以在windows 7 64位的Python3中使用MySQLdb了.這就是我的故事,免得你和我踏進同意個坑然后抬頭問蒼天:"真的有人能搞定這種操蛋事?"
The Setup 安裝Like I said, this is all because I was stupid enough to try to install Django 1.5 on Windows 7 using 64-bit Python 3.2 against a MySQL database server. FUCKIN’ N00B, HOW DARE YOU!
就像我剛剛說的,這一切都是因為我特傻叉想在windows 7 64位下,Python 3.2中安裝Django 1.5 然后使用MySQL數據庫.你也想這么干?真有膽子啊小菜鳥.
The first warning should’ve been that in Django’s docs they explicitly mention that the latest release of MySQLdb doesn’t support Python 3. “No problem”, I thought, “I’ve made a living off of dealing with software build bullshit, I can handle this.”
第一個警告來自Django官方文檔,明確提及最新版的MySQLdb不支持Python 3.(譯注:本文發表于2013年6月,直到2016年的今天MySQLdb依然不支持Py3),"沒問題",我想,"我就算干這行的,我能搞定"
So I had to download a few things to get going:
所以我必須得下幾個東西來搞定這事
1.First I double checked the version of the MySQL server on my computer (which I had installed via Zend Server some time ago). It’s 5.1.43, so then I went hunting on MySQL’s website for a full binary + headers + libs package and found it on http://downloads.mysql.com/ar... So I downloaded the 64-bit zip (I figured since I have 64-bit Python, but it probably didn’t matter). Then I just unpacked that zip to my C:
1.首先我檢查了我電腦上的MySQL版本(通過Zend Server裝的MySQL已經有一段時間了),是5.1.43,我去MySQL官網上找二進制包和鏈接庫,找到了這個 http://downloads.mysql.com/ar...譯注,新鏈接應該是http://dev.mysql.com/download...所以我下載了[這個]3(我想因為我用的是64位python,但是那并不重要),把它解壓到C盤
2.Next I downloaded the MySQL-for-Python-3 package the good Django folks suggested in their docs and unpacked that to a separate folder on C:
2.接下來,下載MySQL-for-Python-3,Django官方建議的包,解壓到C盤的另一個文件夾
3.Also, I already have Visual Studio 2012 installed, so I had all the C compilers and shit at my disposal. Yay.
3.我已經安裝了VS2012,C編譯器的問題就搞定了.Yay.
The Blood and Guts 血雨腥風After much trial and error and googling. This is what I came up with to make it work:
在不斷的GOOGLE和試驗后,下面是我總結出來的方法:
1.Open up a cmd prompt
1.打開CMD
2.Since I have Visual Studio 2012 I had to trick their (not sure if it’s Python’s or MySQLdb’s) stupid build process by pointing them to my Visual Studio 2012 toolset: SET VS90COMNTOOLS=%VS110COMNTOOLS%
2.因為我裝的是VS2012 ,所以我不得不偽造編譯路徑到我的VS2012命令行SET VS90COMNTOOLS=%VS110COMNTOOLS%
3.Then I cd’ed into the MySQL-for-Python-3 directory I unpacked earlier and edited the site.cfg (not in notepad..) file to change the mysql_location to point to the directory I unpacked the MySQL binary+header+libs package to earlier (e.g. mysql_location = C:mysql-5.1.43-winx64)
3.然后cd進入之前解壓的MySQL-for-Python-3的文件夾,編輯site.cfg(不要在記事本中編輯..)文件,更改mysql_location指向之前解壓的MySQL二進制包和鏈接庫的文件夾(例如:mysql_location = C:mysql-5.1.43-winx64)
4.Next, I had to edit the _mysql.c file (again, not in notepad) in MySQL-for-Python-3 to change line 35 from my_config.h to config-win.h
4.接下來,編輯_mysql.c文件(同理,不要在記事本中編輯),把35行的my_config.h改成config-win.h
5.Then, I edited my Python distribution’s C:Python32Libdistutilsmsvc9compiler.py to add a line after line 638 (ld_args.append(‘/MANIFESTFILE:’ + temp_manifest)) as: ld_args.append(‘/MANIFEST’). Why? Cause this dude said so, and it worked.
5.繼續,編輯Python3目錄下Libdistutilsmsvc9compiler.py文件,在638行(譯注:在python3.5中是673行,具體視情況而定)后面增加如下內容(ld_args.append(‘/MANIFESTFILE:’ + temp_manifest))
6.Oh yeah, and I had to edit the MySQL-for-Python-3 file setup_windows.py to change ‘lib’ to ‘lib/opt’ on line 17’s setting of library_dirs cause otherwise it couldn’t find the goddamn MySQL libs.
6.最后,編輯 MySQL-for-Python-3里的setup_windows.py文件,把17行處(位置依然視情況而定)library_dirs里的lib改成lib/opt,因為其他地方找不到該死的MySQL鏈接庫
And then FINALLY I was able to build and install the thing:
最后做的就是編譯和安裝的工作了:
C:MySQL-for-Python-3-master>python setup.py build
running build
running build_py
copying MySQLdbrelease.py -> buildlib.win-amd64-3.2MySQLdb
running build_ext
C:MySQL-for-Python-3-master>python setup.py install
And it fucking worked!
終于他喵的能用了!
So yeah, I’m sure some enlightened Python god will tell me I brought this pain upon myself given my version choices (and please tell me how stupid I am for using Windows), but it’s crap like this that makes me want to run screaming and crying back into Visual Studio/C#’s warm embrace, or at least PHP’s bony grasp…
好吧,我知道一些牛逼的Python大神會告訴我你這是自作自受,選這種版本來搞(還請告訴我這笨蛋到底要怎么用Windows),但那些都是讓我哭著回到Visual Studio/C#的溫暖懷抱或者讓我去學PHP皮毛的廢話罷了
Anyway, if you’re running into similar issues trying to force MySQLdb’s square peg into Python 3’s round hole, I hope this helps.
總之,如果你遇到類似的在python3用MySQLdb問題,我希望這個可以幫到你
文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。
轉載請注明本文地址:http://specialneedsforspecialkids.com/yun/38512.html
摘要:若不出現下方界面則跳過此步啟動后,錯誤提示丟失。處理方法下載安裝運行庫即可。調出命令窗口并輸入出現下圖顯示內容則表示版本安裝成功。將放在盤中文件夾下的,如果是位系統則放在中四打開檢驗環境是否搭建成功出現下方界面則表示搭建成功 一、Python安裝1、Python3官網下載https://www.python.org/downlo... 2、選擇對應系統和版本(注意是32位還是64位,我...
摘要:環境下安裝包經常會有各種環境方面的問題及報錯。所以此次報錯的原因就出來了,缺少了這個頭文件。所以其核心原因在于環境的依賴庫中不存在相關的文件。其它在上有網友提供了一個較為省事兒的解決辦法,直接下載現成的文件到本地進行安裝資源地址。 Windows 環境下安裝python包經常會有各種環境方面的問題及報錯。 最近在python36/37下升級安裝mysqlclient包時產生了下面的錯誤...
摘要:表示需要運行庫,缺少它將會在接來下的過程中彈出類似的提示運行庫下載如果以前安裝過,則不必再裝。回車回車回車即可將服務創建,關閉窗口。下的安裝有一個臨時密碼問題。有空再把下的安裝記錄一下。 最近想更新Web服務器上的軟件,查了一下apache、php、mysql版本都很高了,有些變動還很大,所以先在Win上安裝熟悉一下,下面是安裝配置記錄: 系統:64位Windows7時間:2017年3...
閱讀 2562·2023-04-25 18:13
閱讀 770·2021-11-22 12:10
閱讀 2970·2021-11-22 11:57
閱讀 2138·2021-11-19 11:26
閱讀 2164·2021-09-22 15:40
閱讀 1460·2021-09-03 10:28
閱讀 2704·2019-08-30 15:53
閱讀 1950·2019-08-30 15:44