Pylons is supporting several ways of handling a database: SQLAlchemy, SQLObject, Python DB-API.
In our case, we will use the SQLAlchemy (Python SQL toolkit and Object Relational Mapper) software.
So I will describe here the way to install SQLAlchemy software into the Pylons installation described previously.
First of all you will have to install Python database modules for the databases you want to use.
Here are the databases that I will use (may be not all) in my next posts:
- MySQL (needs the installation of python-mysqldb for Ubuntu 7.10).
- PostgreSQL (needs the installation of python-psycopg2 for Ubuntu 7.10)
- SQLite (integrated in Python 2.5 supplied with Ubuntu 7.10).
So let's install MySQL and PostgreSQL Python databases modules:
sudo apt-get install python-mysqldb
sudo apt-get install python-psycopg2
Then we can install SQLAlchemy:
easy_install --install-dir=$HOME/dev/python SQLAlchemy
The previous command will print in your terminal some logs like the following ones:
Searching for SQLAlchemy
Reading http://cheeseshop.python.org/pypi/SQLAlchemy/
Reading http://www.sqlalchemy.org
Reading http://cheeseshop.python.org/pypi/SQLAlchemy/0.4.0
Best match: SQLAlchemy 0.4.0
Downloading http://pypi.python.org/packages/source/S/SQLAlchemy/SQLAlchemy-0.4.0.tar.gz#md5=c8476f6417a630f36d6046c1faf721e1
Processing SQLAlchemy-0.4.0.tar.gz
Running SQLAlchemy-0.4.0/setup.py -q bdist_egg --dist-dir /tmp/easy_install-Quoosq/SQLAlchemy-0.4.0/egg-dist-tmp-JjywTd
zip_safe flag not set; analyzing archive contents...
sqlalchemy.databases.mysql: module MAY be using inspect.stack
Adding SQLAlchemy 0.4.0 to easy-install.pth file
Installed /home/dma/dev/python/SQLAlchemy-0.4.0-py2.5.egg
Processing dependencies for SQLAlchemy
Finished processing dependencies for SQLAlchemy
And the last thing that we have to do is to test that SQLAlchemy is successfully installed by launching the Python interpreter and by importing SQLAlchemy:
Python 2.5.1 (r251:54863, Oct 5 2007, 13:36:32)
[GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlalchemy
>>> dir(sqlalchemy)
['BLOB', 'BOOLEAN', 'Binary', 'Boolean', 'CHAR', 'CLOB', 'CheckConstraint', 'Column', 'ColumnDefault', 'Constraint', 'DATE', 'DATETIME', 'DECIMAL', 'Date', 'DateTime', 'FLOAT', 'Float', 'ForeignKey', 'ForeignKeyConstraint', 'INT', 'Index', 'Integer', 'Interval', 'MetaData', 'NCHAR', 'Numeric', 'PassiveDefault', 'PickleType', 'PrimaryKeyConstraint', 'SMALLINT', 'Sequence', 'SmallInteger', 'String', 'TEXT', 'TIME', 'TIMESTAMP', 'Table', 'ThreadLocalMetaData', 'Time', 'Unicode', 'UniqueConstraint', 'VARCHAR', '__all__', '__builtins__', '__doc__', '__file__', '__name__', '__path__', '__version__', 'alias', 'and_', 'asc', 'between', 'bindparam', 'case', 'cast', 'create_engine', 'databases', 'delete', 'desc', 'distinct', 'engine', 'engine_from_config', 'except_', 'except_all', 'exceptions', 'exists', 'extract', 'func', 'insert', 'inspect', 'intersect', 'intersect_all', 'join', 'literal', 'literal_column', 'logging', 'modifier', 'name', 'not_', 'null', 'obj', 'or_', 'outerjoin', 'outparam', 'pool', 'queue', 'schema', 'select', 'sql', 'subquery', 'text', 'types', 'union', 'union_all', 'update', 'util']
>>>
To be continued...
No comments:
Post a Comment