AttributeError: module 'functools' has no attribute 'cached_property'

Hi

I am trying to run the stylometric-analysis-main project on win 7 python 3.7. I am getting below mentioned error while running the code
` F:\SCAproj\NLP related\stylometric-analysis-main\stylometric-analysis-main\lib\Basic.py in
3 from .constants import *
4
----> 5 class Basic(object):
6 def init(self, label: str, text: str) → None:
7 super().init()

F:\SCAproj\NLP related\stylometric-analysis-main\stylometric-analysis-main\lib\Basic.py in Basic()
10
11
—> 12 @functools.cached_property
13 def tokens(self):
14 return nltk.word_tokenize(self.raw)
`

error message

AttributeError: module ‘functools’ has no attribute ‘cached_property’

Please tell how to resolve this error message.

Thank you

Windows 7 support eneded on January 14, 2020. Thus, think of a change to a newer Windows version. Python 3.7.0 were released on June 27, 2018. 3.7.17 were released on June 6,2023. Thus, it may never have been tested agains Windows 7.

The error message “AttributeError: module ‘functools’ has no attribute ‘cache’” occurs when the user is trying to use the cache_info() method of a function object that is not wrapped in lru_cache1. To fix this error, the user can try uninstalling the functools package using pip2.

On what functools and lru_cache are about read

[Functools module in Python - GeeksforGeeks](https://Functools module in Python)

[python - How does Lru_cache (from functools) Work? - Stack Overflow](https://How does Lru_cache (from functools) Work?)

Check the part
Difference between @property and @cached_property:
under link below

[Python Functools - cached_property() - GeeksforGeeks](https://Python Functools – cached_property())

You defined:
—> 12 @functools.cached_property

Within the mentioned link I see:
# Using @cached_property
from functools import cached_property

class Sample():

@cached_property

Your message stated that your functools does not even have any attribute like cached_property from my understanding. Thus, do you have the code part where you import things?

Check if the link below has information on what you are finally trying to do with stylometric.

Introduction to stylometry with Python

It’s documented as “New in version 3.8”, so the way to resolve this is to use 3.8 or newer.

3 Likes

Hi Nakul, welcome to the forum.

For future questions, please read the pinned thread in order to understand how to make code and error message appear with proper formatting here. This makes it much easier for us to help you, because of how important the code indentation is in Python.

This doesn’t tell us anything useful. Anyone can make a project and call it “stylometric-analysis-main”.

If you mean, for example, a specific project on GitHub - in general, the best way to get help is to read the documentation there and then check the project’s issue tracker. If it’s someone else’s code and it isn’t working for you “out of box”, chances are the people who wrote it will have the best idea of what is wrong - because they’re the ones responsible for writing it, testing it, making it installable, and telling you how to install it.

Of course, we’re always happy to take a look.

This is straightforward. The code is trying to use a feature that Python 3.7 does not support. Aside from that, Python 3.7 is no longer supported. Neither is Windows 7. Nowadays it’s necessary to keep your tools up to date.

One useful technique for the future is to try copying and pasting the message into a search engine. When I try this, I immediately see several other Github issue tracker reports for other projects, and all of them involve some similar case: the OP is trying to use some code on Python 3.7, and gets told that a newer Python is necessary.

Another way is to try to look up the function or method that broke. If we search only for functools.cached_property, we find out right off the top that it comes from the Python standard library; and if we look for cached_property on that documentation page, it says at the bottom of the section that this is “New in version 3.8.”.

3 Likes