Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change psycopg2 to psycopg2-binary packange #33

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Prashant4900
Copy link

Problem: Whenever I install packages from the requirements.txt file, it shows the error.
Solution: After Changing the psycopg2 to psycopg2-binary the problem is fixed.
OS: Mac

~$ pip3 install -r requirements.txt 
Collecting Django==4.1.4
  Using cached Django-4.1.4-py3-none-any.whl (8.1 MB)
Collecting gunicorn==20.1.0
  Using cached gunicorn-20.1.0-py3-none-any.whl (79 kB)
Collecting whitenoise==6.2.0
  Using cached whitenoise-6.2.0-py3-none-any.whl (19 kB)
Collecting psycopg2==2.9.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
  ╰─> [25 lines of output]
      /Volumes/Work/projects/the_nerdy_nation/the-nerdynation-backend/venv/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 /private/var/folders/fd/hwf9y7m97cjc9429tz4b9hlr0000gn/T/pip-pip-egg-info-cq_2dx8u/psycopg2.egg-info
      writing /private/var/folders/fd/hwf9y7m97cjc9429tz4b9hlr0000gn/T/pip-pip-egg-info-cq_2dx8u/psycopg2.egg-info/PKG-INFO
      writing dependency_links to /private/var/folders/fd/hwf9y7m97cjc9429tz4b9hlr0000gn/T/pip-pip-egg-info-cq_2dx8u/psycopg2.egg-info/dependency_links.txt
      writing top-level names to /private/var/folders/fd/hwf9y7m97cjc9429tz4b9hlr0000gn/T/pip-pip-egg-info-cq_2dx8u/psycopg2.egg-info/top_level.txt
      writing manifest file '/private/var/folders/fd/hwf9y7m97cjc9429tz4b9hlr0000gn/T/pip-pip-egg-info-cq_2dx8u/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.

[notice] A new release of pip available: 22.2.2 -> 22.3.1
[notice] To update, run: pip install --upgrade pip

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.
@nickjj
Copy link
Owner

nickjj commented Jan 12, 2023

Hi,

Are you using an M1 or M2?

It's possible there's no compiled wheels available for this version of Python and your CPU's architecture so it needs to compile those dependencies and now certain dependencies are missing from the Dockerfile.

Switching to -binary is problematic because it's a low performing package meant for easy development not production, it's also stated in their documentation:

The binary package is a practical choice for development and testing but in production it is advised to use the package built from sources.

We would need to hunt down the most minimal apt package to install which provides pg_config.

@Prashant4900
Copy link
Author

Prashant4900 commented Jan 13, 2023

OS: Mac Book Air M1

Thanks for pointing this out. So what is the solution?

@nickjj
Copy link
Owner

nickjj commented Jan 13, 2023

The proper fix would be to ask psycopg2 to compile a wheel for arm64 CPUs for Python 3.10+. They only have amd64 CPU wheels for Linux at https://pypi.org/project/psycopg2/#files.

In the mean time, the Dockerfile would need to be modified to install whatever dependencies it needs to be compiled. This one will be hard for me to test since I don't have an M1.

But:

We would need to hunt down the most minimal apt package to install which provides pg_config

I'm also really surprised this isn't a bigger issue. Lots of people use M1s.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants