I am trying to install Kafka-Python in my MacBook but unable to do so. Below is the version of software installed on my MacBook.
Mac Sierra
Python 3.7.0a4
Python 2.7.10(Default)
Kafka 3.5
First I used the command sudo easy_install pip
to install pip.
Next I tried using pip install kafka-python
to install Kafka-python. But it failed because there are 2 Kafka instances running and it used the older version(2.7). Below is the error I got:
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'
I wanted to install Kafka-python on python 3.7 version but the command again and again used the version 2.7. So finally I followed the below URL to install pip3 followed by Kafka-python and it got installed successfully: http://itsevans.com/install-pip-osx/ .
Post-installation, pip3 is installed in path /Library/Frameworks/Python.framework/Versions/3.7/bin/pip3
. And Kafka-Python is installed in path
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages
.
The folders in the path are :
-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
when I try to import Kafka in terminal or in PyCharm, it does not recognize the Kafka package at all and gives compilation error. In terminal it throws below error:
>>> 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
The Pycharm editor simply does not recognize the Kafka package and hence gives compilation error. Any help on how to configure Kafka-python is greatly appreciated.