abi / autocommit

MIT License
141 stars 14 forks source link

python 3.10.6 import problem #2

Open jakejellinek opened 1 year ago

jakejellinek commented 1 year ago

I did a pip install, using python 3.10.6 and I get this error:-

ImportError: cannot import name 'Mapping' from 'collections' (/usr/lib/python3.10/collections/init.py)

A google search led me to this page which may explain the issue:-

https://bobbyhadz.com/blog/python-importerror-cannot-import-name-mapping-from-collections

abi commented 1 year ago

Let me take a look

SkyHustle commented 1 year ago

I'm on macOS Monterey Version 12.5.1 Python 3.11.1 Using Bash

I get this error when I run 'aicommit'

Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.11/bin/aicommit", line 5, in from autocommit.commit import main File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/autocommit/commit.py", line 2, in from PyInquirer import prompt as py_inquirer_prompt, style_from_dict, Token File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/PyInquirer/init.py", line 6, in from prompt_toolkit.token import Token File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/prompt_toolkit/init.py", line 16, in from .interface import CommandLineInterface File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/prompt_toolkit/interface.py", line 19, in from .application import Application, AbortAction File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/prompt_toolkit/application.py", line 8, in from .key_binding.bindings.basic import load_basic_bindings File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/prompt_toolkit/key_binding/bindings/basic.py", line 9, in from prompt_toolkit.renderer import HeightIsUnknownError File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/prompt_toolkit/renderer.py", line 11, in from prompt_toolkit.styles import Style File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/prompt_toolkit/styles/init.py", line 8, in from .from_dict import * File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/prompt_toolkit/styles/from_dict.py", line 9, in from collections import Mapping ImportError: cannot import name 'Mapping' from 'collections' (/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/collections/init.py)

I scanned through the article @jakejellinek shared. Does reverting back to Python 3.9 solve anything?

abi commented 1 year ago

I'm on Python 3.9.13 locally btw. And that's what I tested against. I can try it tomorrow with 3.10 and 3.11

abi commented 1 year ago

Also, looks like an issue with PyInquirer. I wonder if they have any solutions that I can upgrade the dependency to.

abi commented 1 year ago

I'm having a hard time reproducing this locally with pyenv.

Some potential solutions:

  1. Open up the file where the error is happening (e.g. /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/prompt_toolkit/styles/from_dict.py) and then update from collections import Mapping to from collections.abc import Mapping
  2. Downgrade to Python 3.9
abi commented 1 year ago

Would love some help to actually fix this issue in this package.

ryan6416 commented 1 year ago

@abi I'm on 3.9.13 locally, and I'm getting this error:

Traceback (most recent call last):
  File "/Users/ryanefendy/.pyenv/versions/3.9.13/bin/aicommit", line 5, in <module>
    from autocommit.commit import main
  File "/Users/ryanefendy/.pyenv/versions/3.9.13/lib/python3.9/site-packages/autocommit/commit.py", line 29, in <module>
    prompt = CustomPromptTemplate(
TypeError: Can't instantiate abstract class CustomPromptTemplate with abstract method _prompt_type
JWBWork commented 1 year ago

@abi I'm on 3.9.13 locally, and I'm getting this error:

Traceback (most recent call last):
  File "/Users/ryanefendy/.pyenv/versions/3.9.13/bin/aicommit", line 5, in <module>
    from autocommit.commit import main
  File "/Users/ryanefendy/.pyenv/versions/3.9.13/lib/python3.9/site-packages/autocommit/commit.py", line 29, in <module>
    prompt = CustomPromptTemplate(
TypeError: Can't instantiate abstract class CustomPromptTemplate with abstract method _prompt_type

Can confirm I saw this as well after correcting the from collections.abc import Mapping import statement

I managed to fix it by commenting out the abstract method decorators - after that everything worked as expected!

abi commented 1 year ago

awesome @JWBWork

tkaprol commented 1 year ago

@abi I'm on 3.9.13 locally, and I'm getting this error:

Traceback (most recent call last):
  File "/Users/ryanefendy/.pyenv/versions/3.9.13/bin/aicommit", line 5, in <module>
    from autocommit.commit import main
  File "/Users/ryanefendy/.pyenv/versions/3.9.13/lib/python3.9/site-packages/autocommit/commit.py", line 29, in <module>
    prompt = CustomPromptTemplate(
TypeError: Can't instantiate abstract class CustomPromptTemplate with abstract method _prompt_type

Can confirm I saw this as well after correcting the from collections.abc import Mapping import statement

I managed to fix it by commenting out the abstract method decorators - after that everything worked as expected!

The same happens with 3.8

augustgerro commented 1 year ago

Python 3.10.2:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.10/bin/aicommit", line 5, in <module>
    from autocommit.commit import main
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/autocommit/commit.py", line 2, in <module>
    from PyInquirer import prompt as py_inquirer_prompt, style_from_dict, Token
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/PyInquirer/__init__.py", line 6, in <module>
    from prompt_toolkit.token import Token
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/prompt_toolkit/__init__.py", line 16, in <module>
    from .interface import CommandLineInterface
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/prompt_toolkit/interface.py", line 19, in <module>
    from .application import Application, AbortAction
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/prompt_toolkit/application.py", line 8, in <module>
    from .key_binding.bindings.basic import load_basic_bindings
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/prompt_toolkit/key_binding/bindings/basic.py", line 9, in <module>
    from prompt_toolkit.renderer import HeightIsUnknownError
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/prompt_toolkit/renderer.py", line 11, in <module>
    from prompt_toolkit.styles import Style
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/prompt_toolkit/styles/__init__.py", line 8, in <module>
    from .from_dict import *
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/prompt_toolkit/styles/from_dict.py", line 9, in <module>
    from collections import Mapping
ImportError: cannot import name 'Mapping' from 'collections' (/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/collections/__init__.py)
augustgerro commented 1 year ago

@abi I'm on 3.9.13 locally, and I'm getting this error:

Traceback (most recent call last):
  File "/Users/ryanefendy/.pyenv/versions/3.9.13/bin/aicommit", line 5, in <module>
    from autocommit.commit import main
  File "/Users/ryanefendy/.pyenv/versions/3.9.13/lib/python3.9/site-packages/autocommit/commit.py", line 29, in <module>
    prompt = CustomPromptTemplate(
TypeError: Can't instantiate abstract class CustomPromptTemplate with abstract method _prompt_type

Can confirm I saw this as well after correcting the from collections.abc import Mapping import statement

I managed to fix it by commenting out the abstract method decorators - after that everything worked as expected!

Sorry, what exactly you commented?

augustgerro commented 1 year ago

I have changed

class CustomPromptTemplate(BasePromptTemplate, BaseModel):
    template: str

    def format(self, **kwargs) -> str:
        c_kwargs = {k: v for k, v in kwargs.items()}
        return self.template.format(**c_kwargs)

to

class CustomPromptTemplate(BasePromptTemplate, BaseModel):
    template: str

    def format_prompt(self, **kwargs) -> str:
        c_kwargs = {k: v for k, v in kwargs.items()}
        return self.template.format(**c_kwargs)

    def format(self, **kwargs) -> str:
        return self.format_prompt(**kwargs)

now it looks like it's works,

Other issue from OpenAI API:

Retrying langchain.llms.openai.completion_with_retry.._completion_with_retry in 4.0 seconds as it raised RateLimitError: You exceeded your current quota, please check your plan