如何使用Python-kazoo库?

2024-05-12 20:56:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我计划使用Python kazoo库作为动物园管理员。这都是关于Python的问题,这里根本不是zookeeper,我想是指如何正确使用Python kazoo。。

我对python完全不熟悉,所以我不知道如何开始,以及如何使用kazoo来连接zookeeper。

这是我读到的开始用kazoo做动物园管理员的文件。

http://kazoo.readthedocs.org/en/latest/install.html

在维基中,他们要求安装kazoo。他们在用pip命令?

皮普在这里做什么?我现在使用的是windows,所以我安装了cygwin和python。我正在使用Python2.7.3

host@D-SJC-00542612 ~
$ python
Python 2.7.3 (default, Dec 18 2012, 13:50:09)
[GCC 4.5.3] on cygwin

现在我所做的是-我从上面的网站复制了这个命令-pip install kazoo,并在我的cygwin命令提示符下运行它。

host@D-SJC-00542612 ~
$ pip install kazoo
Downloading/unpacking kazoo
  Running setup.py egg_info for package kazoo

    warning: no previously-included files found matching '.gitignore'
    warning: no previously-included files found matching '.travis.yml'
    warning: no previously-included files found matching 'Makefile'
    warning: no previously-included files found matching 'run_failure.py'
    warning: no previously-included files matching '*' found under directory 'sw'
    warning: no previously-included files matching '*pyc' found anywhere in distribution
    warning: no previously-included files matching '*pyo' found anywhere in distribution
Downloading/unpacking zope.interface>=3.8.0 (from kazoo)
  Running setup.py egg_info for package zope.interface

    warning: no previously-included files matching '*.dll' found anywhere in distribution
    warning: no previously-included files matching '*.pyc' found anywhere in distribution
    warning: no previously-included files matching '*.pyo' found anywhere in distribution
    warning: no previously-included files matching '*.so' found anywhere in distribution
Requirement already satisfied (use --upgrade to upgrade): distribute in c:\python27\lib\site-packages (from zope.interface>=3.8.0->kazoo)
Installing collected packages: kazoo, zope.interface
  Running setup.py install for kazoo

    warning: no previously-included files found matching '.gitignore'
    warning: no previously-included files found matching '.travis.yml'
    warning: no previously-included files found matching 'Makefile'
    warning: no previously-included files found matching 'run_failure.py'
    warning: no previously-included files matching '*' found under directory 'sw'
    warning: no previously-included files matching '*pyc' found anywhere in distribution
    warning: no previously-included files matching '*pyo' found anywhere in distribution
  Running setup.py install for zope.interface

    warning: no previously-included files matching '*.dll' found anywhere in distribution
    warning: no previously-included files matching '*.pyc' found anywhere in distribution
    warning: no previously-included files matching '*.pyo' found anywhere in distribution
    warning: no previously-included files matching '*.so' found anywhere in distribution
    building 'zope.interface._zope_interface_coptimizations' extension
    ********************************************************************************
    WARNING:

            An optional code optimization (C extension) could not be compiled.

            Optimizations for this package will not be available!
    ()
    Unable to find vcvarsall.bat
    ********************************************************************************
    Skipping installation of C:\Python27\Lib\site-packages\zope\__init__.py (namespace package)
    Installing C:\Python27\Lib\site-packages\zope.interface-4.0.5-py2.7-nspkg.pth
Successfully installed kazoo zope.interface
Cleaning up...

安装是否正确?现在我可以开始用python编写代码来连接zookeeper了吗?

很抱歉问了这么多愚蠢的问题,因为我对python没有任何背景,所以在这里学习一点。。

这都是关于Python的问题,我想根本不是动物园管理员。。


Tags: installnoinpyzopefilesinterfacedistribution
1条回答
网友
1楼 · 发布于 2024-05-12 20:56:52

pip是安装软件包的常用方法。它从pypi查询和下载包。 Kazoo已按照日志语句安装。试试看。

您应该可以在where python is installed\lib\site-packages\kazoo找到包。

您应该尝试加载(导入)包而不出现错误:

from kazoo.client import KazooClient

在你启动动物园管理员之后。zookeeper配置将包含客户端端口详细信息。

tickTime=2000
dataDir=...../zookeeperdata/cluster/server1/data
clientPort=2181
initLimit=5

用这个连接到zookeeper。

# Create a client and start it
zk = KazooClient(hosts='127.0.0.1:2181')
zk.start()

# Now you can do the regular zookepper API calls
# Ensure some paths are created required by your application
zk.ensure_path("/app/someservice") 

# In the end, stop it
zk.stop()

相关问题 更多 >