python3连接oracle数据库真操蛋_为64位Windows7的Python3安装MySQLdb
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),"沒問題",我想,"我就算干這行的,我能搞定"
Getting Started
準備開始
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問題,我希望這個可以幫到你
總結
以上是生活随笔為你收集整理的python3连接oracle数据库真操蛋_为64位Windows7的Python3安装MySQLdb的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 顺其自然网名134个
- 下一篇: 招桃花的网名125个