简体   繁体   English

如何使用Python kazoo库?

[英]How to use Python kazoo library?

I am planning to use Python kazoo library for Zookeeper. 我打算将Python kazoo库用于Zookeeper。 It's all about Python question here not zookeeper at all I guess meaning how to use Python kazoo properly.. 这完全是关于Python的问题,我想这根本不是zookeeper,这意味着如何正确使用Python kazoo。

I am totally new to python so I have no idea how to get going and how to use kazoo to connect with zookeeper. 我对python完全陌生,所以我不知道如何开始以及如何使用kazoo与zookeeper连接。

This is the document I was reading to start using kazoo for Zookeeper. 这是我正在阅读的文档,开始将kazoo用于Zookeeper。

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

In that wiki, they have asked to install kazoo. 在该Wiki中,他们要求安装kazoo。 And they are using some pip command for that? 他们为此使用一些pip命令吗?

What does pip do here? 点子在这里做什么? And I am currently using windows so I have cygwin installed and python installed as well. 而且我目前正在使用Windows,因此我同时安装了cygwin和python。 I am using Python 2.7.3 我正在使用Python 2.7.3

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

Now what I did is - I copied this command exactly as it is from the above website - pip install kazoo and ran it on my cygwin command prompt. 现在我要做的是-我完全从上述网站复制了此命令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...

Does it got installed properly? 安装正确吗? Now I can start writing code in python to connect with zookeeper? 现在我可以开始用python编写代码以与zookeeper连接了吗?

Sorry for asking all these dumb questions as I don't have any background with python so learning little bit here.. 抱歉问了所有这些愚蠢的问题,因为我没有python的背景知识,所以在这里学到点知识。

It's all about Python question here not zookeeper at all I guess.. 我想这全是关于Python问题的,不是动物园管理员。

pip is common way to install packages. pip是安装软件包的常用方法。 It queries and downloads the packages from pypi . 它查询并从pypi下载软件包。 Kazoo has been installed as per the log statements. 按照日志语句安装了Kazoo。 Give it a try. 试试看。

you should be able to find the package at where python is installed\\lib\\site-packages\\kazoo . 您应该能够where python is installed\\lib\\site-packages\\kazoo找到该软件包。

You should try to load (import) the package without errors: 您应该尝试加载(导入)程序包而不会出现错误:

from kazoo.client import KazooClient

After you have started the zookeeper. 启动动物园管理员之后。 Your zookeeper configuration will have the client port details. 您的zookeeper配置将包含客户端端口详细信息。

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

Use that to connect to zookeeper. 使用它连接到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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM