我正在尝试在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。但它失败了,因为有2个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包并出现编译错误。在终端中,它会抛出错误:
>>> 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的帮助都非常感谢。
答案 0 :(得分:1)
似乎python3.7破坏了兼容性。 最新版本的kafka-python(1.4.3)修复了此问题:“修复了python 3.7支持:从SimpleProducer(dpkp#1454)删除'async'关键字”
答案 1 :(得分:0)
我不知道你是否解决了这个问题。但是这个答案有助于解决这个问题。
编辑: 基本上,问题在于使用旧版本的 Kafka 包。您需要安装当前版本才能解决此问题。 尝试使用 pip cmd 安装 'kafka-python' 包。这对我有用,希望对你也有用。