question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Got SyntaxError around self.async while import KafkaProducer on python 3.7.4

See original GitHub issue

I’m using Python 3.7.4 in PyCharm 2019.1.4 (PY-191.8026.44). I have installed kafka-1.3.5. When I import KafkaProducer, I get an error:

(venv-py) D:\PycharmProjects\FCOP>python
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul  8 2019, 19:29:22) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from kafka import KafkaProducer
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\PycharmProjects\FCOP\venv-py\lib\site-packages\kafka\__init__.py", line 23, in <module>
    from kafka.producer import KafkaProducer
  File "D:\PycharmProjects\FCOP\venv-py\lib\site-packages\kafka\producer\__init__.py", line 4, in <module>
    from .simple import SimpleProducer
  File "D:\PycharmProjects\FCOP\venv-py\lib\site-packages\kafka\producer\simple.py", line 54
    return '<SimpleProducer batch=%s>' % self.async
                                                  ^
SyntaxError: invalid syntax
>>>

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:6

github_iconTop GitHub Comments

14reactions
tvoinarovskyicommented, Jun 7, 2020

Ohh, sorry, I get the issue. You seem to have kafka package installed, that is a forbidden package and is not updated. Please:

  • remove both kafka and kafka-python packages using pip uninstall command
  • Reinstall only kafka-python package.

You need to remove both packages to ensure python loads the kafka module properly. Sorry for the trouble. Relates to https://github.com/dpkp/kafka-python/issues/1253

5reactions
theabhisheksinhacommented, Mar 13, 2020

I am presently running on:

PS C:\Apache\Kafka\kafka_2.13-2.4.0\bin\windows> pip install kafka-python Requirement already satisfied: kafka-python in c:\python3.8.1\lib\site-packages (2.0.1)

yet I face this issue :

PS C:\Apache\Kafka\kafka_2.13-2.4.0\bin\windows> python .\test.py Traceback (most recent call last): File “.\test.py”, line 5, in from kafka import KafkaConsumer File “C:\python3.8.1\lib\site-packages\kafka_init_.py”, line 23, in from kafka.producer import KafkaProducer File “C:\python3.8.1\lib\site-packages\kafka\producer_init_.py”, line 4, in from .simple import SimpleProducer File “C:\python3.8.1\lib\site-packages\kafka\producer\simple.py”, line 54 return ‘’ % self.async ^

Any thoughts on how to fix this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Got SyntaxError around self.async while ... - Stack Overflow
In my case it solved by installing "kafka-python" package . python -m pip install kafka ...
Read more >
Got SyntaxError around self.async while import ... - Pinterest
Got SyntaxError around self.async while import KafkaProducer on python 3.7.4 · Issue ... Full Stack Data Science projects centered around Apache.
Read more >
Syntaxerror On "Self.Async" When Running Python Kafka ...
I'm using Python 3.7.4 in PyCharm 2019.1.4 PY191.8026.44.I have installed kafka1.3.5.When I import KafkaProducer I get an error:. I'm using Python ...
Read more >
Syntax error when running my program (Python 3)
[Example code]-Syntax error when running my program (Python 3). Related Posts. How to import a module in Python in a file that ...
Read more >
pyatspi is not Python 3.7 compatible due to using "async" as a ...
pyatspi uses "async" as a attribute/argument name: ... line 114 self.async = False # not fully supported yet ^ SyntaxError: invalid syntax.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found