1

I am attempting to install psycopg2 for use within a project. I am also using asdf in order to manage my python versions. I have tried doing this inside of a venv but I get the same error so to keep things simple let's just say I want to install it outside of a venv.

❯ cat .tool-versions
nodejs 15.9.0
python 3.10.8
postgres 11.8

❯ which pip
~/.asdf/shims/pip

❯ which pg_config
~/.asdf/shims/pg_config

❯ pg_config --version
PostgreSQL 11.8

❯ pip install psycopg2
Collecting psycopg2
  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
  ╰─> [9 lines of output]
      ~/.asdf/installs/python/3.10.8/lib/python3.10/site-packages/setuptools/config/setupcfg.py:463: SetuptoolsDeprecationWarning: The license_file parameter is deprecated, use license_files instead.
        warnings.warn(msg, warning_class)
      running egg_info
      creating <redacted_temp_folder>/T/pip-pip-egg-info-3tgyoyym/psycopg2.egg-info
      writing <redacted_temp_folder>/T/pip-pip-egg-info-3tgyoyym/psycopg2.egg-info/PKG-INFO
      writing dependency_links to <redacted_temp_folder>/T/pip-pip-egg-info-3tgyoyym/psycopg2.egg-info/dependency_links.txt
      writing top-level names to <redacted_temp_folder>/T/pip-pip-egg-info-3tgyoyym/psycopg2.egg-info/top_level.txt
      writing manifest file '<redacted_temp_folder>/T/pip-pip-egg-info-3tgyoyym/psycopg2.egg-info/SOURCES.txt'
      Error: b'No version is set for command pg_config\n'
      [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.

Everything I can find seems to revolve around installing pg_config or postgresql or some other dependency but no one else seems to have encountered this exact error. The best I can figure is that somehow the process python setup.py egg_info is not using the same $PATH as the root command, maybe because it's working directory is outside of the scope of my .tool-versions? Any help is appreciated.

Jon McClung
  • 1,619
  • 20
  • 28

1 Answers1

1

It appears that the correct way to get pip to find pg_config is to set the postgres version globally:

asdf global postgres 11.8

source

Jon McClung
  • 1,619
  • 20
  • 28
  • Is there no other way to define a local postgres_config? I mean probably you want to have multiple pg_config files for different projects? – Ndrslmpk Feb 18 '23 at 21:51
  • @Ndrslmpk I think you would just use `local` instead of `global` if you want a different version for a project. – Jon McClung Feb 20 '23 at 16:50