open-reaction-database / ord-schema

Schema for the Open Reaction Database
https://open-reaction-database.org
Apache License 2.0
92 stars 26 forks source link

psycopg2 fails installation #654

Closed marcosfelt closed 1 year ago

marcosfelt commented 1 year ago

Describe the bug Installing on Mac OS X and Linux fail due to use of pyscog2

To Reproduce

Collecting psycopg2>=2.8.5
  Using cached psycopg2-2.9.5.tar.gz (384 kB)
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [23 lines of output]
      running egg_info
      creating /tmp/pip-pip-egg-info-318tzeve/psycopg2.egg-info
      writing /tmp/pip-pip-egg-info-318tzeve/psycopg2.egg-info/PKG-INFO
      writing dependency_links to /tmp/pip-pip-egg-info-318tzeve/psycopg2.egg-info/dependency_links.txt
      writing top-level names to /tmp/pip-pip-egg-info-318tzeve/psycopg2.egg-info/top_level.txt
      writing manifest file '/tmp/pip-pip-egg-info-318tzeve/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>).

      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

Additional context I think it would be better to use pyscog2-binary here: https://www.psycopg.org/docs/install.html

FanwangM commented 1 year ago

Did you set up your PostgreSQL? You will need to set up pg_config for your machine if using pip, I guess. https://stackoverflow.com/questions/11618898/pg-config-executable-not-found. I think for setting up a local working environment, pyscog2-binary would be OK. But for deployment, maybe better to use psycog2, https://www.psycopg.org/docs/install.html#:~:text=psycopg%20vs%20psycopg%2Dbinary,binary%20as%20a%20module%20dependency.

If you are using conda for virtual envionment management, you can try conda install psycopg2, which worked on my Linux machine. @marcosfelt

marcosfelt commented 1 year ago

Thanks, I will give this a try. Also, is Postgres a necessary install? Could it be made optional for the ORM? I figure this is a barrier for a lot of people.

FanwangM commented 1 year ago

If you are in a Linux machine, I think the easiest way is to install postgres with conda. Otherwise, you may want to explore other options to have a system-wide Postgress installed, which is not so enjoyable. @marcosfelt

skearnes commented 1 year ago

Right. The issue here is that you need psycopg2 instead of psycopg2-binary; the former requires that you have the postgres dev headers installed so you can compile the module locally.

As a workaround, you can install psycopg2-binary and it will automagically serve as a drop-in replacement for psycopg2.

More details: https://www.psycopg.org/docs/install.html#psycopg-vs-psycopg-binary