SQL alchemy installation,simplified

Image

In the previous article of the series Introductory Tutorial to Python’s SQLAlchemy, we learned how to write database code using SQLAlchemy’s declaratives. In this article, we are going to learn how to install SQLAlchemy on Linux, Mac OS X and Windows.

Installing SQLAlchemy on Windows

Before installing SQLAlchemy on Windows, you need to install Python using its Windows installer. You can download one of Python’s Windows MSI installer at Python’s release page. You can install it by double clicking the .msi file.

After you have installed Python on your Windows system, you can download the source code of SQLAlchemy from SQLAlchemy Download Page and install it using its setup.py script.

 

 
1
2
3
4
5
6
7
C:\> C:\Python27\python.exe .\setup.py install
running install
running build
running build_py
   ……
Plain-Python build succeeded.
*********************************

 

Installing SQLAlchemy on Linux

It’s recommended that we create a virtualenv before we install SQLAlchemy. So, let’s go ahead and do that:

 

 
1
2
3
4
5
6
$ virtualenv sqlalchemy-workspace
New python executable in sqlalchemy-workspace/bin/python
Installing distribute………………..done.
Installing pip……………done
$ cd sqlalchemy-workspace
$ source bin/activate

 

Then, the easiest way to install SQLAlchemy is to use Python’s package manager pip:

 

 
1
2
3
4
5
6
7
8
9
10
$ pip install sqlalchemy
Downloading/unpacking sqlalchemy
  Downloading SQLAlchemy-0.8.1.tar.gz (3.8Mb): 3.8Mb downloaded
  Running setup.py egg_info for package sqlalchemy
    
    ……
 
    no previously-included directories found matching ‘doc/build/output’
Successfully installed sqlalchemy
Cleaning up…

 

Installing SQLAlchemy on Mac OS X

Installing SQLAlchemy on Mac OS X is relatively the same as Linux. Once you have created a Python virtualenv following the same steps as Linux, you can install SQLAlchemy using the following commands:

 

 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$ virtualenv sqlalchemy-workspace
New python executable in sqlalchemy-workspace/bin/python
Installing setuptools…………done.
Installing pip……………done.
$ cd sqlalchemy-workspace
$ source bin/activate
$ pip install sqlalchemy
Downloading/unpacking sqlalchemy
  Downloading SQLAlchemy-0.8.2.tar.gz (3.8MB): 3.8MB downloaded
  Running setup.py egg_info for package sqlalchemy
 
  ……
 
    no previously-included directories found matching ‘doc/build/output’
Successfully installed sqlalchemy
Cleaning up…

 

That’s it. You have successfully installed SQLAlchemy and you can start writing declarative models using the new SQLAlchemy-powered virtualenv right away.

Summary

Under Linux or Mac OS X, it’s recommended to install SQLAlchemy inside a virtualenv using pip since it’s more convenient than installing it from the source code. While under Windows, you have to install it from the source code using a system-wide Python installation.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s