pymongo是一个驱动程序,用python编写的高性能,文件为基础的数据库。
pymongo是一个驱动程序,,用python编写的高性能,文件为基础的数据库。
下载并安装。
[monogdb@localhost bin]$wget #md5=12e12163e6cc22993808900fb9629252
--21:21:18--
正在解析主机 pypi.python.org... 82.94.164.168, 2001:888:2000:d::a8
connecting to pypi.python.org|82.94.164.168|:80... 已连接。
已发出 http 请求,正在等待回应... 200 ok
长度:146895 (143k) [application/x-gzip]
saving to: `pymongo-1.9.tar.gz'
100%[============================================================================================>] 146,895 66.9k/s in 2.1s
21:21:21 (66.9 kb/s) - `pymongo-1.9.tar.gz' saved [146895/146895]
[monogdb@localhost bin]$tar zxvf pymongo-1.9.tar.gz
pymongo-1.9/
pymongo-1.9/doc/
pymongo-1.9/ez_setup.py/
pymongo-1.9/pymongo/
pymongo-1.9/setup.cfg
pymongo-1.9/setup.py
......
pymongo-1.9/bson/timestamp.py
pymongo-1.9/bson/tz_util.py
[monogdb@localhost bin]$ cd pymongo-1.9
[monogdb@localhost pymongo-1.9]$ ls
bson ez_setup.py license pkg-info pymongo.egg-info setup.cfg test
doc gridfs manifest.in pymongo readme.rst setup.py tools
第一次执行安装的时候报错,权限不够
[monogdb@localhost pymongo-1.9]$ python setup.py install
running install
error: can't create or remove files in install directory
the following error occurred while trying to add or remove files in the
installation directory:
[errno 13] permission denied: '/usr/lib64/python2.4/site-packages/test-easy-install-11661.write-test'
the installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:
/usr/lib64/python2.4/site-packages/
perhaps your account does not have write access to this directory? if the
installation directory is a system-owned directory, you may need to sign in
as the administrator or root account. if you do not have administrative
access to this machine, you may wish to choose a different installation
directory, preferably one that is listed in your pythonpath environment
variable.
以root权限给monogdb赋予访问/usr/lib64/python2.4/site-packages/的权限:
[root@localhost ~]#chown monogdb:monogdb /usr/lib64/python2.4/site-packages/
再次安装。。
[monogdb@localhost pymongo-1.9]$python setup.py install
running install
running bdist_egg
running egg_info
writing pymongo.egg-info/pkg-info
writing top-level names to pymongo.egg-info/top_level.txt
writing dependency_links to pymongo.egg-info/dependency_links.txt
processing pymongo-1.9-py2.4-linux-x86_64.egg
creating /usr/lib64/python2.4/site-packages/pymongo-1.9-py2.4-linux-x86_64.egg
extracting pymongo-1.9-py2.4-linux-x86_64.egg to /usr/lib64/python2.4/site-packages
adding pymongo 1.9 to easy-install.pth file
installed /usr/lib64/python2.4/site-packages/pymongo-1.9-py2.4-linux-x86_64.egg
processing dependencies for pymongo==1.9
finished processing dependencies for pymongo==1.9
测试python环境中与monogdb的交互。
[monogdb@localhost pymongo-1.9]$ python
python 2.4.3 (#1, jan 21 2009, 01:11:33)
[gcc 4.1.2 20071124 (red hat 4.1.2-42)] on linux2
type help, copyright, credits or license for more information.
>>> import pymongo
>>> conn = pymongo.connection(host=127.0.0.1)
>>> db=conn.test
>>> db
database(connection('127.0.0.1', 27017), u'test')
>>> str={id:1,'val':hello monogdb}
>>> db.test.save(str)
objectid('4e3fe5d8e138232e61000000')
>>> cursor = db.test.find()
>>> for i in cursor:
... print i
...
{u'_id': objectid('4e3fe5d8e138232e61000000'), u'id': 1, u'val': u'hello monogdb'}
>>>
成功!!