8

I'm using Python 3.7 on my Windows

This error occurs while running every code:

Traceback (most recent call last):
  File "test.py", line 1, in <module>
    import nltk
  File "C:\Users\HP\AppData\Local\Programs\Python\Python37\lib\site-packages\nltk\__init__.py", line 99, in <module>
    from nltk.internals import config_java
  File "C:\Users\HP\AppData\Local\Programs\Python\Python37\lib\site-packages\nltk\internals.py", line 11, in <module>
    import subprocess
  File "C:\Users\HP\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line 50, in <module>
    import signal
  File "C:\Users\HP\AppData\Local\Programs\Python\Python37\lib\signal.py", line 3, in <module>
    from functools import wraps as _wraps
  File "C:\Users\HP\AppData\Local\Programs\Python\Python37\lib\functools.py", line 21, in <module>
    from collections import namedtuple
  File "C:\Users\HP\AppData\Local\Programs\Python\Python37\lib\collections\__init__.py", line 22, in <module>
    from keyword import iskeyword as _iskeyword
  File "C:\Users\HP\Desktop\tweepy\keyword.py", line 1, in <module>
    import re
  File "C:\Users\HP\AppData\Local\Programs\Python\Python37\lib\re.py", line 297, in <module>
    @functools.lru_cache(_MAXCACHE)
AttributeError: module 'functools' has no attribute 'lru_cache'

How to fix it?

Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
F.Sh
  • 89
  • 1
  • 2

2 Answers2

6

It looks like someone published a functools package on pypi, so if you had run:

# don't run this!
pip install functools

You may have accidentally installed that package. If you encounter this error, I would:

pip uninstall functools

To make sure that the functools you are using are the base package functools.

(I ended up here because I attempted to use functools.cache, which seems to only be present in Python 3.8, not earlier.)

duhaime
  • 25,611
  • 17
  • 169
  • 224
0

I had the same error recently and it was because I had a file called functools.py in my project. Renaming it fixed the issue.

Michael Millar
  • 1,364
  • 2
  • 24
  • 46