psycopg / psycopg2

PostgreSQL database adapter for the Python programming language
https://www.psycopg.org/
Other
3.31k stars 503 forks source link

ImportError: DLL load failed while importing _psycopg: The specified module could not be found. #1703

Closed pd-25 closed 3 months ago

pd-25 commented 3 months ago

This is a bug tracker If you have a question, such has "how do you do X with Python/PostgreSQL/psycopg2" please write to the mailing list or open a question instead.

Please complete the following information:

config.py: import os from dotenv import load_dotenv

as config is not where main.py, so we have to declaer the path

from pathlib import Path

env_path = Path(".") / ".env"

print(env_path)

load_dotenv(dotenv_path=env_path)

class Setting: PROJECT_TITLE: str = "Pradipta Blog Apis" PROJECT_VERSION: str = "0.1.0"

POSTGRES_USER: str = os.getenv("POSTGRES_USER")
POSTGRES_PASSWORD: str = os.getenv("POSTGRES_PASSWORD")
POSTGRES_SERVER: str = os.getenv("POSTGRES_SERVER")
POSTGRES_PORT: str = os.getenv("POSTGRES_PORT")
POSTGRES_DB: str = os.getenv("POSTGRES_DB")
DATABASE_URL: str = f"postgresql://{POSTGRES_USER}:{POSTGRES_PASSWORD}@{POSTGRES_SERVER}:{POSTGRES_PORT}/{POSTGRES_DB}"

settings = Setting()


session.py: from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker

from core.config import settings from typing import Generator

SQLALCHEMY_DATABASE_URL = settings.DATABASE_URL print("Database url is ", SQLALCHEMY_DATABASE_URL) engine = create_engine(SQLALCHEMY_DATABASE_URL) print("Database url is-------- ", SQLALCHEMY_DATABASE_URL) SESSIONLOCAL = sessionmaker(autoflush=False, autocommit=False, bind=engine)

def get_db() -> Generator: try: db = SESSIONLOCAL() yield db finally: db.close()


requirements.txt: fastapi==0.100.0 uvicorn==0.22.0

SQLAlchemy==2.0.13 psycopg2==2.9.6

python-dotenv==1.0.0

alembic==1.11.1

pydantic[email]

passlib[bcrypt]

all are installed and virtualenv activated.. --------------Error---------------- When Running unvicorn main:app --reload getting this error

vn
dvarrazzo commented 3 months ago

This is an installation error and I cannot debug it.

pd-25 commented 3 months ago

@dvarrazzo Yes It is some version issue. The versions I was installing was not compatible with environment. I installed the latest it worked for me.