Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sqlacodegen showing Argspec not found

can anyone please help me with it. I was trying to use sqlacodegen with postgresql to autogenerate the database models from my database, but it is constantly showing me this import error

>sqlacodegen postgresql://postgres:j1234@localhost:4040/db1
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\user\AppData\Local\Programs\Python\Python311\Scripts\sqlacodegen.exe\__main__.py", line 4, in <module>
  File "C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\site-packages\sqlacodegen\main.py", line 11, in <module>
    from sqlacodegen.codegen import CodeGenerator
  File "C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\site-packages\sqlacodegen\codegen.py", line 9, in <module>
    from inspect import ArgSpec
ImportError: cannot import name 'ArgSpec' from 'inspect' (C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\inspect.py)

i am working with python 3.11, postgresql, sqlalchemy 2.0.15, and sqlacodegen 2.3.0

I want to autogenerate database models from my database for my fastapi. I am also open to any kind of sqlacodegen alternatives

like image 239
Juned SK Avatar asked Feb 26 '26 00:02

Juned SK


2 Answers

I encountered this issue as well. The problem arises because ArgSpec has been removed in Python 3.11.

The solution is to open the /site-packages/sqlacodegen/codegen.py file in your text editor. Then, delete the line that includes from inspect import ArgSpec at line 9. Additionally, remove lines 486 and 488, replacing them with return False, and then run your command again. It should work without any issues.

like image 52
yusufusta Avatar answered Feb 28 '26 21:02

yusufusta


To add onto what others have mentioned, SQLAcodegen-v2 doesn't have this issue and runs fine on Python 3.11 (with SQLAlchemy 2.0)

like image 23
Hawawa Avatar answered Feb 28 '26 23:02

Hawawa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!