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

ImportError Postgresql #572

Open
Warglaive opened this issue Oct 14, 2023 · 1 comment
Open

ImportError Postgresql #572

Warglaive opened this issue Oct 14, 2023 · 1 comment

Comments

@Warglaive
Copy link

OS: Windows 10
Python: 3.11
databases version: 0.8.0
database backend: postgresql
database driver: asyncpg

Issue stacktrace:
`D:\project-management-service\API\env\Scripts\python.exe -m uvicorn main:app --reload
INFO: Will watch for changes in these directories: ['D:\project-management-service\API']
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO: Started reloader process [17016] using StatReload
D:\project-management-service\API\env\Lib\site-packages\pydantic_internal_config.py:317: UserWarning: Valid config keys have changed in V2:

  • 'orm_mode' has been renamed to 'from_attributes'
    warnings.warn(message, UserWarning)
    Process SpawnProcess-1:
    Traceback (most recent call last):
    File "D:\Program Files\Python311\Lib\multiprocessing\process.py", line 314, in _bootstrap
    self.run()
    File "D:\Program Files\Python311\Lib\multiprocessing\process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
    File "D:\project-management-service\API\env\Lib\site-packages\uvicorn_subprocess.py", line 76, in subprocess_started
    target(sockets=sockets)
    File "D:\project-management-service\API\env\Lib\site-packages\uvicorn\server.py", line 61, in run
    return asyncio.run(self.serve(sockets=sockets))
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "D:\Program Files\Python311\Lib\asyncio\runners.py", line 190, in run
    return runner.run(main)
    ^^^^^^^^^^^^^^^^
    File "D:\Program Files\Python311\Lib\asyncio\runners.py", line 118, in run
    return self.loop.run_until_complete(task)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "D:\Program Files\Python311\Lib\asyncio\base_events.py", line 653, in run_until_complete
    return future.result()
    ^^^^^^^^^^^^^^^
    File "D:\project-management-service\API\env\Lib\site-packages\uvicorn\server.py", line 68, in serve
    config.load()
    File "D:\project-management-service\API\env\Lib\site-packages\uvicorn\config.py", line 467, in load
    self.loaded_app = import_from_string(self.app)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "D:\project-management-service\API\env\Lib\site-packages\uvicorn\importer.py", line 21, in import_from_string
    module = importlib.import_module(module_str)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "D:\Program Files\Python311\Lib\importlib_init
    .py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "", line 1204, in _gcd_import
    File "", line 1176, in _find_and_load
    File "", line 1147, in _find_and_load_unlocked
    File "", line 690, in _load_unlocked
    File "", line 940, in exec_module
    File "", line 241, in call_with_frames_removed
    File "D:\project-management-service\API\main.py", line 5, in
    from config.config import Config
    File "D:\project-management-service\API\config\config.py", line 31, in
    database_session = db_session.DBSession()
    ^^^^^^^^^^^^^^^^^^^^^^
    File "D:\project-management-service\API\config\db_session.py", line 19, in init
    self.async_database = databases.Database(DATABASE_URL)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "D:\project-management-service\API\env\Lib\site-packages\databases\core.py", line 66, in init
    backend_cls = import_from_string(backend_str)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "D:\project-management-service\API\env\Lib\site-packages\databases\importer.py", line 21, in import_from_string
    raise exc from None
    File "D:\project-management-service\API\env\Lib\site-packages\databases\importer.py", line 18, in import_from_string
    module = importlib.import_module(module_str)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "D:\Program Files\Python311\Lib\importlib_init
    .py", line 126, in import_module
    return _bootstrap.gcd_import(name[level:], package, level)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "D:\project-management-service\API\env\Lib\site-packages\databases\backends\postgres.py", line 6, in
    from sqlalchemy.dialects.postgresql import pypostgresql
    ImportError: cannot import name 'pypostgresql' from 'sqlalchemy.dialects.postgresql' (D:\project-management-service\API\env\Lib\site-packages\sqlalchemy\dialects\postgresql_init
    .py)`

Please correct me if I did not report he issue properly.

@Warglaive
Copy link
Author

The problem has a very simple solution.
Go to: site-packages\databases\backends\postgres.py
and Replace from sqlalchemy.dialects.postgresql import pypostgresql
with
from sqlalchemy.dialects import postgresql as pypostgresql

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

1 participant