在Python系列SQLAlchemy入門教程系列的前一篇文章中,我們學習了如何使用SQLAlchemy的聲明來編寫數據庫代碼。在本文中,我們將學習如何在linux,Mac OS X和Windows上安裝SQLAlchemy。
在Windows上安裝SQLAlchemy
在Windows上安裝SQLAlchemy之前,需要使用Windows安裝程序來安裝Python。您可以在Python的發行頁面下載Python的Windows MSI安裝程序之一。您可以通過雙擊.msi
文件來安裝它。
在Windows系統上安裝Python之后,您可以從SQLAlchemy下載頁面下載 SQLAlchemy的源代碼,并使用其setup.py腳本進行安裝。
1234567 | C:/>C:/Python27/python.exe./setup.pyinstallrunninginstallrunningbuildrunningbuild_py ......Plain-Pythonbuildsucceeded.********************************* |
在Linux上安裝SQLAlchemy
建議我們在安裝SQLAlchemy之前創建一個virtualenv。所以,讓我們繼續做:
123456 | $virtualenvsqlalchemy-workspaceNewpythonexecutableinsqlalchemy-workspace/bin/pythonInstallingdistribute....................done.Installingpip...............done$cdsqlalchemy-workspace$sourcebin/activate |
然后,安裝SQLAlchemy的最簡單的方法是使用Python的包管理器pip
:
12345678910 | $pipinstallsqlalchemyDownloading/unpackingsqlalchemy DownloadingSQLAlchemy-0.8.1.tar.gz(3.8Mb):3.8Mbdownloaded Runningsetup.pyegg_infoforpackagesqlalchemy ...... noPReviously-includeddirectoriesfoundmatching'doc/build/output'SuccessfullyinstalledsqlalchemyCleaningup... |
在Mac OS X上安裝SQLAlchemy
在Mac OS X上安裝SQLAlchemy與Linux相比相同。按照與Linux相同的步驟創建Python virtualenv之后,可以使用以下命令安裝SQLAlchemy:
12345678910111213141516 | $virtualenvsqlalchemy-workspaceNewpythonexecutableinsqlalchemy-workspace/bin/pythonInstallingsetuptools............done.Installingpip...............done.$cdsqlalchemy-workspace$sourcebin/activate$pipinstallsqlalchemyDownloading/unpackingsqlalchemy DownloadingSQLAlchemy-0.8.2.tar.gz(3.8MB):3.8MBdownloaded Runningsetup.pyegg_infoforpackagesqlalchemy ...... nopreviously-includeddirectoriesfoundmatching'doc/build/output'SuccessfullyinstalledsqlalchemyCleaningup... |
而已。您已成功安裝SQLAlchemy,您可以立即使用新的SQLAlchemy-powered virtualenv 開始編寫聲明性模型。
概要
在Linux或Mac OS X下,建議在使用pip的virtualenv中安裝SQLAlchemy,因為它比從源代碼安裝SQLAlchemy更方便。在Windows下,您必須使用系統范圍的Python安裝從源代碼安裝它。
參考鏈接:http://pythoncentral.io/how-to-install-sqlalchemy/
http://www.tuicool.com/articles/aueyMn
http://blog.csdn.net/billvsme/article/details/50197197