I followed the instructions from here when researching on how to install psycopg2 on my new Macbook pro with M1 chip.
brew install libpq --build-from-source
brew install openssl
export LDFLAGS="-L/opt/homebrew/opt/openssl@1.1/lib -L/opt/homebrew/opt/libpq/lib"
export CPPFLAGS="-I/opt/homebrew/opt/openssl@1.1/include -I/opt/homebrew/opt/libpq/include"
pip3 install psycopg2
installation was successful, and this was the output when i tried to run the last line again
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: psycopg2 in /Users/yvonnetan/Library/Python/3.8/lib/python/site-packages (2.9.3)
hence it seems that the installation is successful, but when i run my codes, the same error appears:
code:
DATABASE_URI = f"postgresql://{credentials.user}:{credentials.pwd}@{credentials.host}:{credentials.port}/{credentials.db}"
engine = create_engine(DATABASE_URI)
error:
ModuleNotFoundError                       Traceback (most recent call last)
/Users/yvonnetan/Documents/people-data-science/product-metrics/notebooks/product_metrics_automation.ipynb Cell 3' in <cell line: 10>()
      7 import credentials
      9 DATABASE_URI = f"postgresql://{credentials.user}:{credentials.pwd}@{credentials.host}:{credentials.port}/{credentials.db}"
---> 10 engine = create_engine(DATABASE_URI)
File <string>:2, in create_engine(url, **kwargs)
File ~/opt/anaconda3/lib/python3.9/site-packages/sqlalchemy/util/deprecations.py:309, in deprecated_params.<locals>.decorate.<locals>.warned(fn, *args, **kwargs)
    302     if m in kwargs:
    303         _warn_with_version(
    304             messages[m],
    305             versions[m],
    306             version_warnings[m],
    307             stacklevel=3,
    308         )
--> 309 return fn(*args, **kwargs)
File ~/opt/anaconda3/lib/python3.9/site-packages/sqlalchemy/engine/create.py:560, in create_engine(url, **kwargs)
    558         if k in kwargs:
    559             dbapi_args[k] = pop_kwarg(k)
--> 560     dbapi = dialect_cls.dbapi(**dbapi_args)
    562 dialect_args["dbapi"] = dbapi
    564 dialect_args.setdefault("compiler_linting", compiler.NO_LINTING)
File ~/opt/anaconda3/lib/python3.9/site-packages/sqlalchemy/dialects/postgresql/psycopg2.py:782, in PGDialect_psycopg2.dbapi(cls)
    780 @classmethod
    781 def dbapi(cls):
--> 782     import psycopg2
    784     return psycopg2
ModuleNotFoundError: No module named 'psycopg2'
engine = create_engine(DATABASE_URI)
Can anyone help me please?
 
     
    