Prepare to rewrite this site with tornado, but an error occurred while discovering import tornado.database.
Copy Code code as follows:
[Root@lee ~]# python
Python 2.7.4 (default, APR 11 2013, 17:08:33)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
Type ' help ', ' copyright ', ' credits ' or ' license ' for the more information.
>>> Import Tornado.web
>>> Import Tornado.database
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
Importerror:no Module named database
>>>
A lot of tutorials on the Internet is clearly written this module, how can I hint to find this module? Do I have no reason to install MYSQLDB?
Copy Code code as follows:
[Root@lee tornado]# python
Python 2.7.4 (default, APR 11 2013, 17:08:33)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
Type ' help ', ' copyright ', ' credits ' or ' license ' for the more information.
>>> Import MySQLdb
>>>
MYSQLDB module has been installed, it does not appear to be caused by the MySQLdb module. I tornado again, and the result is no database module.
Python module is a py file, I inverted tornado directory to see, and sure enough, did not database.py this module:
Copy Code code as follows:
[Root@lee ~]# Find/usr-name tornado
/usr/lib/python2.6/site-packages/tornado-3.0.1-py2.6.egg/tornado
/usr/local/lib/python2.7/site-packages/tornado-3.0.1-py2.7.egg/tornado
/usr/local/lib/python2.7/site-packages/tornado
[Root@lee ~]# Cd/usr/local/lib/python2.7/site-packages/tornado
[Root@lee tornado]# ls
auth.py escape.pyc __init__.pyc netutil.pyc tcpserver.py web.pyc
Auth.pyc gen.py ioloop.py options.py tcpserver.pyc websocket.py
autoreload.py gen.pyc ioloop.pyc options.pyc template.py websocket.pyc
AUTORELOAD.PYC httpclient.py iostream.py Platform Template.pyc wsgi.py
CA-CERTIFICATES.CRT httpclient.pyc iostream.pyc process.py test WSGI.PYC
concurrent.py httpserver.py locale.py Process.pyc testing.py
Concurrent.pyc httpserver.pyc locale.pyc simple_httpclient.py testing.pyc
curl_httpclient.py httputil.py log.py Simple_httpclient.pyc util.py
Curl_httpclient.pyc httputil.pyc log.pyc stack_context.py util.pyc
escape.py __init__.py netutil.py Stack_context.pyc web.py
[Root@lee tornado]#
So to Tornado official website looked at the document, originally is tornado3.0 version after the abolition of the database module, but launched a similar database module torndb, I saw the source code is basically mysqldb simple package.
Download torndb,https://github.com/bdarnell/torndb
Installation:
Copy Code code as follows:
[Root@lee software]# Unzip Torndb-master.zip
Archive:torndb-master.zip
Ab862d70f293304f3a37527dff549eb6818063f7
creating:torndb-master/
Inflating:torndb-master/.gitignore
Inflating:torndb-master/readme.rst
creating:torndb-master/doc/
Inflating:torndb-master/doc/makefile
inflating:torndb-master/doc/conf.py
Inflating:torndb-master/doc/index.rst
inflating:torndb-master/setup.py
inflating:torndb-master/torndb.py
Inflating:torndb-master/tox.ini
[Root@lee software]# CD Torndb-master
[Root@lee torndb-master]# ls
Doc Readme.rst setup.py torndb.py Tox.ini
[Root@lee torndb-master]# python setup.py build
Running Build
Running Build_py
Creating build
Creating Build/lib
Copying torndb.py-> Build/lib
[Root@lee torndb-master]# python setup.py install
Running Install
Running Build
Running Build_py
Running Install_lib
Copying build/lib/torndb.py->/usr/local/lib/python2.7/site-packages
byte-compiling/usr/local/lib/python2.7/site-packages/torndb.py to Torndb.pyc
Running Install_egg_info
Writing/usr/local/lib/python2.7/site-packages/torndb-0.1-py2.7.egg-info
[Root@lee torndb-master]#
Install it, try to pour it into the torndb module.
Copy Code code as follows:
[Root@lee torndb-master]# python
Python 2.7.4 (default, APR 11 2013, 17:08:33)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
Type ' help ', ' copyright ', ' credits ' or ' license ' for the more information.
>>> Import Torndb
>>>
OK, it's done.
In fact, using TORNDB and directly using the MYSQLDB module to manipulate the database is the same, look at a person's liking
For documentation on TORNDB please see here: http://torndb.readthedocs.org/en/latest/