luanteylo / hads_

1 stars 1 forks source link

ModuleNotFoundError: No module named 'psycopg2' #3

Open LucianaMarques opened 2 years ago

LucianaMarques commented 2 years ago

Description

During database recreation, there is an issue with not finding module psycopg2. It looks like it doesn't get installed with requirements.txt, so I'm creating this issue for investigation on why.

What I Did

Traceback from main command:

$ python3 client.py recreate_db
NotifyConfig: env var NOTIFY_PWD not found.
Traceback (most recent call last):
  File "/Users/lucianadacostamarques/Documents/Mestrado/hads_/client.py", line 144, in <module>
    main()
  File "/Users/lucianadacostamarques/Documents/Mestrado/hads_/client.py", line 136, in main
    loader = Loader(args=parser.parse_args())
  File "/Users/lucianadacostamarques/Documents/Mestrado/hads_/control/util/loader.py", line 121, in __init__
    self.__get_execution_id()
  File "/Users/lucianadacostamarques/Documents/Mestrado/hads_/control/util/loader.py", line 232, in __get_execution_id
    repo = PostgresRepo()
  File "/Users/lucianadacostamarques/Documents/Mestrado/hads_/control/repository/postgres_repo.py", line 32, in __init__
    self.engine = create_engine(connection_string)
  File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/__init__.py", line 500, in create_engine
    return strategy.create(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/strategies.py", line 87, in create
    dbapi = dialect_cls.dbapi(**dbapi_args)
  File "/usr/local/lib/python3.9/site-packages/sqlalchemy/dialects/postgresql/psycopg2.py", line 753, in dbapi
    import psycopg2
ModuleNotFoundError: No module named 'psycopg2'

When trying to install with pip:

$ pip3 install psycopg2
Collecting psycopg2
  Using cached psycopg2-2.9.3.tar.gz (380 kB)
    ERROR: Command errored out with exit status 1:
     command: /usr/local/opt/python@3.9/bin/python3.9 -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/hg/7rjk1bsj58n_1j_hgf96rq4h0000gn/T/pip-install-wuxadyo0/psycopg2_4a3067e1d2904eb4bbc7af5b0aa6106d/setup.py'"'"'; __file__='"'"'/private/var/folders/hg/7rjk1bsj58n_1j_hgf96rq4h0000gn/T/pip-install-wuxadyo0/psycopg2_4a3067e1d2904eb4bbc7af5b0aa6106d/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /private/var/folders/hg/7rjk1bsj58n_1j_hgf96rq4h0000gn/T/pip-pip-egg-info-awhp9jq0
         cwd: /private/var/folders/hg/7rjk1bsj58n_1j_hgf96rq4h0000gn/T/pip-install-wuxadyo0/psycopg2_4a3067e1d2904eb4bbc7af5b0aa6106d/
    Complete output (23 lines):
    running egg_info
    creating /private/var/folders/hg/7rjk1bsj58n_1j_hgf96rq4h0000gn/T/pip-pip-egg-info-awhp9jq0/psycopg2.egg-info
    writing /private/var/folders/hg/7rjk1bsj58n_1j_hgf96rq4h0000gn/T/pip-pip-egg-info-awhp9jq0/psycopg2.egg-info/PKG-INFO
    writing dependency_links to /private/var/folders/hg/7rjk1bsj58n_1j_hgf96rq4h0000gn/T/pip-pip-egg-info-awhp9jq0/psycopg2.egg-info/dependency_links.txt
    writing top-level names to /private/var/folders/hg/7rjk1bsj58n_1j_hgf96rq4h0000gn/T/pip-pip-egg-info-awhp9jq0/psycopg2.egg-info/top_level.txt
    writing manifest file '/private/var/folders/hg/7rjk1bsj58n_1j_hgf96rq4h0000gn/T/pip-pip-egg-info-awhp9jq0/psycopg2.egg-info/SOURCES.txt'

    Error: pg_config executable not found.

    pg_config is required to build psycopg2 from source.  Please add the directory
    containing pg_config to the $PATH or specify the full executable path with the
    option:

        python setup.py build_ext --pg-config /path/to/pg_config build ...

    or with the pg_config option in 'setup.cfg'.

    If you prefer to avoid building psycopg2 from source, please install the PyPI
    'psycopg2-binary' package instead.

    For further information please check the 'doc/src/install.rst' file (also at
    <https://www.psycopg.org/docs/install.html>).

    ----------------------------------------
WARNING: Discarding https://files.pythonhosted.org/packages/d1/1e/b450599a27b1809bccbd4e369f397cb18dc56b875778d961f9ae180b54b7/psycopg2-2.9.3.tar.gz#sha256=8e841d1bf3434da985cc5ef13e6f75c8981ced601fd70cc6bf33351b91562981 (from https://pypi.org/simple/psycopg2/) (requires-python:>=3.6). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

[.....]
luanteylo commented 2 years ago

I don't know how to do it on macos. But you need to install the psycopg2-binary (see link below)

https://stackoverflow.com/questions/12906351/importerror-no-module-named-psycopg2

LucianaMarques commented 2 years ago

Thanks for the input! Found this issue that might help: https://github.com/psycopg/psycopg2/issues/1200

We could update the psycopg2 version to the latest, which they say is compatible with macos, but wanted to confirm with you first because there's always the possibility of creating new problems when upgrading packages.