"
This article is part of in the series
Last Updated: Wednesday 29th December 2021

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.

[shell]
C:\> C:\Python27\python.exe .\setup.py install
running install
running build
running build_py
......
Plain-Python build succeeded.
*********************************
[/shell]

Installing SQLAlchemy on Linux

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

[shell]
$ virtualenv sqlalchemy-workspace
New python executable in sqlalchemy-workspace/bin/python
Installing distribute....................done.
Installing pip...............done
$ cd sqlalchemy-workspace
$ source bin/activate
[/shell]

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

[shell]
$ 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...
[/shell]

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:

[shell]
$ 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...
[/shell]

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.

About The Author