我试图在我的MacBook中安装Kafka-Python,但无法做到这一点。下面是安装在我的MacBook上的软件版本。
Mac Sierra
Python 3.7.0a4
Python 2.7.10(Default)
Kafka 3.5
首先,我使用命令sudo easy_install pip
安装pip。
接下来我试着用pip install kafka-python
来安装Kafka-python,但是失败了,因为有两个Kafka示例在运行,而且它使用的是旧版本(2.7)。
Exception:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/commands/install.py", line 342, in run
prefix=options.prefix_path,
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_set.py", line 784, in install
**kwargs
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_install.py", line 851, in install
self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_install.py", line 1064, in move_wheel_files
isolated=self.isolated,
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/wheel.py", line 345, in move_wheel_files
clobber(source, lib_dir, True)
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/wheel.py", line 316, in clobber
ensure_dir(destdir)
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/utils/__init__.py", line 83, in ensure_dir
os.makedirs(path)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py", line 157, in makedirs
mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/kafka_python-1.3.5.dist-info'
我想在python 3.7版本上安装Kafka-python,但命令一次又一次地使用2.7版本。所以最后我按照下面的URL安装pip3,然后安装Kafka-python,它成功安装:http://itsevans.com/install-pip-osx/.
安装后,pip3安装在路径/Library/Frameworks/Python.framework/Versions/3.7/bin/pip3
中,Kafka-Python安装在路径/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages
中。
路径中的文件夹包括:
-rw-rw-r-- 1 root admin 126 Jan 24 20:52 easy_install.py
drwxrwxr-x 34 root admin 1088 Jan 24 20:52 setuptools
drwxrwxr-x 6 root admin 192 Jan 24 20:52 pkg_resources
drwxrwxr-x 12 root admin 384 Jan 24 20:52 setuptools-28.8.0.dist-info
drwxrwxr-x 23 root admin 736 Jan 24 20:52 pip
drwxrwxr-x 10 root admin 320 Jan 24 20:52 pip-9.0.1.dist-info
drwxrwxr-x 4 root admin 128 Jan 24 20:52 __pycache__
drwxr-xr-x 18 ******* admin 576 Feb 2 12:26 wheel
drwxr-xr-x 11 ******* admin 352 Feb 2 12:26 wheel-0.30.0.dist-info
drwxr-xr-x 24 ******* admin 768 Feb 2 12:28 kafka
drwxr-xr-x 9 ******* admin 288 Feb 2 12:28 kafka_python-1.3.5.dist-info
当我尝试在终端或PyCharm中导入Kafka时,它根本无法识别Kafka包并给出编译错误。2在终端中,它抛出以下错误:
>>> import kafka
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/kafka/__init__.py", line 23, in <module>
from kafka.producer import KafkaProducer
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/kafka/producer/__init__.py", line 4, in <module>
from .simple import SimpleProducer
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/kafka/producer/simple.py", line 54
return '<SimpleProducer batch=%s>' % self.async
^
SyntaxError: invalid syntax
Pycharm编辑器无法识别Kafka包,因此会出现编译错误。如有任何关于如何配置Kafka-python的帮助,我们将不胜感激。
2条答案
按热度按时间nhjlsmyf1#
似乎python3.7破坏了兼容性,kafka-python的最新版本(1.4.3)修复了这个问题:“python 3.7支持的修复:从SimpleProducer中删除'async'关键字(dpkp #1454)”
来源:https://github.com/dpkp/kafka-python/releases/tag/1.4.3
5lhxktic2#
我不知道你是否解决了这个问题。但是这个答案有助于解决这个问题。
Git集线器链接
编辑:基本上,问题出在Kafka软件包,它使用的是旧版本。你需要安装当前版本来解决这个问题。**尝试使用pip cmd安装'kafka-python'软件包。这个对我有效,希望对你也有效。