poetry fails to install psycopg2-binary in python 3.12 (macos)
Asked Answered
G

2

6

I cannot get psycopg2-binary package to install via poetry in python3.12.


pyproject.toml

[tool.poetry]
name = "my_project"

[tool.poetry.dependencies]
psycopg2-binary = "*"

[build-system]
requires = ["poetry-core>=1.8.1"]
build-backend = "poetry.core.masonry.api"

Installing the project in python 3.11 works. psycopg2-binary installs.

When I try to install with poetry in a python 3.12 environment, the following error occurs:

poetry install --with dev --sync
Installing dependencies from lock file

Package operations: 1 install, 0 updates, 0 removals

  • Installing psycopg2-binary (2.9.9): Failed

  ChefBuildError

  Backend subprocess exited when trying to invoke get_requires_for_build_wheel
  
  running egg_info
  writing psycopg2_binary.egg-info/PKG-INFO
  writing dependency_links to psycopg2_binary.egg-info/dependency_links.txt
  writing top-level names to psycopg2_binary.egg-info/top_level.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>).
  
  

  at ~/.pyenv/versions/3.12.0/envs/poetry312/lib/python3.12/site-packages/poetry/installation/chef.py:166 in _prepare
      162│ 
      163│                 error = ChefBuildError("\n\n".join(message_parts))
      164│ 
      165│             if error is not None:
    → 166│                 raise error from None
      167│ 
      168│             return path
      169│ 
      170│     def _prepare_sdist(self, archive: Path, destination: Path | None = None) -> Path:

Note: This error originates from the build backend, and is likely not a problem with poetry but with psycopg2-binary (2.9.9) not supporting PEP 517 builds. You can verify this by running 'pip wheel --no-cache-dir --use-pep517 "psycopg2-binary (==2.9.9)"'.

What confuses me is the error looks like it's attempting to install pyscopg2 not psycopg2-binary.

I don't fully understand the note at the bottom.

Note: This error originates from the build backend, and is likely not a problem with poetry but with psycopg2-binary (2.9.9) not supporting PEP 517 builds. You can verify this by running 'pip wheel --no-cache-dir --use-pep517 "psycopg2-binary (==2.9.9)"'.

When I execute pip wheel --no-cache-dir --use-pep517 "psycopg2-binary (==2.9.9)" the following returns:

$ pip wheel --no-cache-dir --use-pep517 "psycopg2-binary (==2.9.9)"
Collecting psycopg2-binary==2.9.9
  Downloading psycopg2_binary-2.9.9-cp312-cp312-macosx_11_0_arm64.whl.metadata (4.4 kB)
Downloading psycopg2_binary-2.9.9-cp312-cp312-macosx_11_0_arm64.whl (2.6 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.6/2.6 MB 2.4 MB/s eta 0:00:00
Saved ./psycopg2_binary-2.9.9-cp312-cp312-macosx_11_0_arm64.whl

I don't understand what this verified....

In addition, I'm able to install psycopg2-binary via pip just fine.


  • MacOS 14 (sonoma) M2
  • Poetry 1.7.0
Gloss answered 9/11, 2023 at 15:3 Comment(0)
G
2

Well, this appears to have been some sort of poetry cache issue.

I ran this:

poetry cache clear . --all

Then was able to install psycopg2-binary just fine.

Gloss answered 9/11, 2023 at 15:45 Comment(4)
I have same problem related to ChefBuildError but with different package: aiohttp (3.8.6). poetry cache clear doesn't solve my issue.Gruber
Does yours install in 3.11 but not in 3.12?Gloss
I dont mention it in the post, but through the course of troubleshooting, I also ended up completely reinstalling poetry in a slightly different way. It was installed natively using the system python (3.11), but is now installed in a separate pyenv virtualenv (3.12). I wouldn't think that should have any major impact since the problem occurred in both environments, but I really have no idea.Gloss
Clean installation fixed the problemGruber
G
1

A radical solution to this problem is to reinstall poetry. A clear cache didn't work for me, but a clean installation worked.

Gruber answered 9/11, 2023 at 16:29 Comment(1)
I'm happy that worked but it just feels so wrong to not understand why.Gloss

© 2022 - 2024 — McMap. All rights reserved.