Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: module 'time' has no attribute 'clock' | Error Log | Potential Resolution #431

Open
Techfluent-au opened this issue Dec 28, 2023 · 2 comments

Comments

@Techfluent-au
Copy link

Techfluent-au commented Dec 28, 2023

It appears that you are encountering an error related to a Python script or application that you are running, and it's not directly related to PowerShell or setting environment variables. The error message suggests that there is an issue with the Python code you are executing, particularly in a file related to the Pygments library used for syntax highlighting.

The error message "AttributeError: module 'time' has no attribute 'clock'" indicates that there is an attempt to access the 'clock' attribute in the 'time' module, which is no longer available in Python 3.8 and later.

To resolve this issue, you may need to update the code that is using the deprecated 'clock' attribute. You can replace it with 'perf_counter' or 'process_time' depending on the context. Here's how you can update the code:

`//Replace this line that uses 'clock'
//time_func = time.clock

//Use 'perf_counter' instead (for measuring elapsed time)
//time_func = time.perf_counter

// or

//Use 'process_time' instead (for measuring CPU time)
time_func = time.process_time`

Once you've made this change, try running the script or application again. If you don't have access to the code or it's part of a third-party library, you may need to update the library to a version that is compatible with Python 3.8 and later.

Error Log

Unhandled Exception: Traceback (most recent call last): File "C:\Users\npall\mentat\mentat\session.py", line 238, in run_main await self._main() File "C:\Users\npall\mentat\mentat\session.py", line 168, in _main parsed_llm_response = await conversation.get_model_response() File "C:\Users\npall\mentat\mentat\conversation.py", line 272, in get_model_response response = await self._stream_model_response( File "C:\Users\npall\mentat\mentat\conversation.py", line 217, in _stream_model_response parsed_llm_response = await parser.stream_and_parse_llm_response( File "C:\Users\npall\mentat\mentat\parsers\parser.py", line 203, in stream_and_parse_llm_response ) = self._special_block( File "C:\Users\npall\mentat\mentat\parsers\block_parser.py", line 158, in _special_block display_information = DisplayInformation( File "<attrs generated init mentat.parsers.change_display_helper.DisplayInformation>", line 10, in __init__ self.__attrs_post_init__() File "C:\Users\npall\mentat\mentat\parsers\change_display_helper.py", line 67, in __attrs_post_init__ self.lexer = _get_lexer(self.file_name) File "C:\Users\npall\mentat\mentat\parsers\change_display_helper.py", line 20, in _get_lexer lexer: Lexer = get_lexer_for_filename(file_path) File "C:\Users\npall\.conda\envs\mentat\lib\site-packages\pygments\lexers\__init__.py", line 225, in get_lexer_for_filename res = find_lexer_class_for_filename(_fn, code) File "C:\Users\npall\.conda\envs\mentat\lib\site-packages\pygments\lexers\__init__.py", line 185, in find_lexer_class_for_filename for cls in find_plugin_lexers(): File "C:\Users\npall\.conda\envs\mentat\lib\site-packages\pygments\plugin.py", line 73, in find_plugin_lexers yield entrypoint.load() File "C:\Users\npall\.conda\envs\mentat\lib\importlib\metadata\__init__.py", line 171, in load module = import_module(match.group('module')) File "C:\Users\npall\.conda\envs\mentat\lib\importlib\__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1050, in _gcd_import File "<frozen importlib._bootstrap>", line 1027, in _find_and_load File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 688, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 883, in exec_module File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed File "C:\Users\npall\.conda\envs\mentat\lib\site-packages\choco\ext\pygmentplugin.py", line 16, in <module> from choco import compat File "C:\Users\npall\.conda\envs\mentat\lib\site-packages\choco\compat.py", line 124, in <module> time_func = time.clock AttributeError: module 'time' has no attribute 'clock'

@jakethekoenig
Copy link
Member

I'm not sure exactly what choco's problem is here but we can fix this problem by catching the attribute error here. Not sure if there's a more principled solution or this will lead to other errors @PCSwingle

@PCSwingle
Copy link
Member

@Techfluent-au, could you let us know what version of python you're using, what version of conda you're using, and what version of choco you're using? I have a hunch this might be fixed if you updated conda, or maybe choco, and then remade your venv (although I'm not sure). The time.clock function was removed in Python 3.8, but it looks like something related to either choco or conda is using it in a 'compat' file which I don't have. Unfortunately, I'm not too familiar with either conda or choco, so I can't say I'm entirely certain on what the error could be.

@jakethekoenig I'm hesitant to do that because I don't think this is a widespread problem and probably has to do with the environment (I think most likely something outdated with choco or conda), and it would stop anybody using mentat with this error from discovering that they have a problem with their environment that doesn't allow pygment formatting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants