-
Notifications
You must be signed in to change notification settings - Fork 254
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
sqlacodegen failing with Error: import name 'ArgSpec' from 'inspect' #239
Comments
As a workaround you can install on MacOS / Linux: # Install pipx
python -m pip install pipx
python -m pipx ensurepath
# Install pyenv
curl https://pyenv.run | bash
# or brew install pyenv --HEAD
eval "$(pyenv init -)"
# Install your python versions
pyenv install 3.11.0
pyenv install 3.10.8
# Switch to Python 3.10.8
pyenv shell 3.10.8
python --version
# Python 3.10.8
# Install sqlacodegen using Python 3.10.8
python -m pipx install sqlacodegen --python $(which python)
# Inject your SQL driver to sqlacodegen package inside pipx
python -m pipx inject sqlacodegen mysqlclient
# switch back to python 3.11.0
pyenv local 3.11.0
pyenv global 3.11.0
pyenv shell 3.11.0
python --version
# Python 3.11.0
# Verify sqlacodegen runs with 3.10.8
pipx list
package sqlacodegen 2.3.0, installed using Python 3.10.8
- sqlacodegen
sqlacodegen --version
# 2.3.0 |
Have you tried the 3.0 release candidate? |
Hey @jpmx and @agronholm, |
I had to shift my focus to other projects while I was working on finishing sqlacodegen 3.0. This is on my TODO list, but behind a couple other projects where I am trying to get new major releases out too. So, I can't give you a timeline. |
Ok @agronholm thanks for the help :-) |
This solved it for me with Python 3.11.1! Had to run the following with poetry: λ poetry add git+https://github.com/agronholm/sqlacodegen.git
Updating dependencies
Resolving dependencies... (0.7s)
Writing lock file
Package operations: 2 installs, 0 updates, 0 removals
• Installing inflect (6.0.2)
• Installing sqlacodegen (3.0.0rc1.post22 f05d99e) then was able to use it as expected λ sqlacodegen --generator dataclasses sqlite:///lunch.db
from __future__ import annotations
from dataclasses import dataclass, field
from datetime import datetime
from sqlalchemy import Column, Integer, String, TIMESTAMP, Table, Text
from sqlalchemy.orm import registry
mapper_registry = registry()
metadata = mapper_registry.metadata
t_lunch_list = Table(
'lunch_list', metadata,
Column('restaurants', Text, unique=True),
Column('option', Text)
)
t_recent_lunch = Table(
'recent_lunch', metadata,
Column('restaurants', Text, unique=True),
Column('date', TIMESTAMP)
)
@mapper_registry.mapped
@dataclass
class Restaurant:
__tablename__ = 'restaurant'
__sa_dataclass_metadata_key__ = 'sa'
id: int = field(init=False, metadata={'sa': Column(Integer, primary_key=True)})
restaurant: str = field(metadata={'sa': Column(String, nullable=False)})
option: str = field(metadata={'sa': Column(String, nullable=False)}) My pyproject.toml looks like this [tool.poetry]
name = "lunch"
version = "0.1.0"
description = ""
authors = ["pythoninthegrass <[email protected]>"]
readme = "README.md"
[tool.poetry.dependencies]
python = "^3.11"
PySimpleGUI = "^4.56.0"
passlib = "^1.7.4"
flet = "^0.3.2"
tk = "^0.1.0"
sqlmodel = "^0.0.8"
sqlacodegen = {git = "https://github.com/agronholm/sqlacodegen.git"}
[tool.poetry.dev-dependencies]
icecream = "^2.1.1"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api" |
@agronholm You're amazing and thank you for your work with this. For those of you using Pipenv simply add the following to your sqlacodegen = {git = "https://github.com/agronholm/sqlacodegen.git"} Using
Thanks to @pythoninthegrass for the heads up w/Poetry. |
I had same problem in python 3.11
I tried change 'ArgSpec' to 'FullArgSpec' directly in 'sqlacodegen' package. Seems it is dangerous to modifying code direct. |
You can just install the latest release candidate: |
#258 |
What's P38? |
Python 38, and confirming P311 this same.. - solved by #comment as sugeestion |
you can edit codegen.py at line 9 -> |
Best to use the latest pre-release though. |
modify the source of sqlacodegen\codegen.py in function:
change to :
|
As mentioned, it's best to use the pre-release
as per #239 (comment) |
thanks, pre-release works well |
Thanks everyone, version 3.0.0 rc3 works well for me too. |
https://pypi.org/project/sqlacodegen/ |
Or |
the sqlacodengen library is failing on first install not even showing help
Apparently the ArgSpec has been removed after a long deprecation period
in python/cpython#28618, replaced by FullArgSpec. which is causing it to break need help.
Also, confirmed with SQLAlchemy team - https://groups.google.com/g/sqlalchemy/c/OGrv9S8fPLw
I even tried downgrading the SQLAlchemy to version 1.3.24 as mentioned in the readme of sqlacodegen => 0.8.x - 1.3.x
still no luck!!!
Error -
PS C:\Users\User\Github\PythonPOC> sqlacodegen --help
Traceback (most recent call last):
File "", line 198, in _run_module_as_main
File "", line 88, in _run_code
File "C:\Users\User\AppData\Roaming\Python\Python311\Scripts\sqlacodegen.exe_
main.py", line 4, in
File "C:\Users\User\AppData\Roaming\Python\Python311\site-packages\sqlacodegen
n\main.py", line 11, in
from sqlacodegen.codegen import CodeGenerator
File "C:\Users\User\AppData\Roaming\Python\Python311\site-packages\sqlacodegen
n\codegen.py", line 9, in
from inspect import ArgSpec
ImportError: cannot import name 'ArgSpec' from 'inspect' (C:\Program Files\Pytho
on311\Lib\inspect.py)
The text was updated successfully, but these errors were encountered: