Error while installing psycopg2 using pip [duplicate] - python

This question already has answers here:
pg_config executable not found
(54 answers)
Closed 6 months ago.
I am trying to run docker in django using this command docker build -t myimage . Now the docker file tries to run the RUN pip install -r /app/requirements.txt --no-cache-dir but when ot gets to the Downloading psycopg2-2.9.3.tar.gz (380 kB) section, it throws the error.
NOTE: i do not have psycopg2 in my requirements.txt file only the psycopg2-binary.
requirements.txt file
...
dj-database-url==0.5.0
Django==3.2.7
django-filter==21.1
django-formset-js-improved==0.5.0.2
django-heroku==0.3.1
psycopg2-binary
python-decouple==3.5
...
Downloading pytz-2022.2.1-py2.py3-none-any.whl (500 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 500.6/500.6 kB 2.6 MB/s eta 0:00:00
Collecting psycopg2
Downloading psycopg2-2.9.3.tar.gz (380 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 380.6/380.6 kB 2.7 MB/s eta 0:00:00
Preparing metadata (setup.py): started
Preparing metadata (setup.py): finished with status '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-383i9hb2/psycopg2.egg-info
writing /tmp/pip-pip-egg-info-383i9hb2/psycopg2.egg-info/PKG-INFO
writing dependency_links to /tmp/pip-pip-egg-info-383i9hb2/psycopg2.egg-info/dependency_links.txt
writing top-level names to /tmp/pip-pip-egg-info-383i9hb2/psycopg2.egg-info/top_level.txt
writing manifest file '/tmp/pip-pip-egg-info-383i9hb2/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.
The command '/bin/sh -c pip install -r /app/requirements.txt --no-cache-dir' returned a non-zero code: 1
Dockerfile
FROM python:3.8.13-slim-buster
WORKDIR /app
COPY ./my_app ./
RUN pip install --upgrade pip --no-cache-dir
RUN pip install -r /app/requirements.txt --no-cache-dir
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
# CMD ["gunicorn", "main_app.wsgi:application", "--bind"]

You need to install the system dependencies (pg_*) if you want to use psycopg2, otherwise, you can use the all-in-one package that include them by remplacing psycopg2 by psycopg2-binary

Related

pip failing to install psycopg2-binary on ubuntu 22.04 with python 3.10 [duplicate]

This question already has answers here:
pg_config executable not found
(54 answers)
Closed 5 months ago.
seeing this on Ubuntu 22.04 which has python 3.10
pip3 install psycopg2-binary==2.8.5
Defaulting to user installation because normal site-packages is not writeable
Collecting psycopg2-binary==2.8.5
Using cached psycopg2-binary-2.8.5.tar.gz (381 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-qc0tg_5p/psycopg2_binary.egg-info
writing /tmp/pip-pip-egg-info-qc0tg_5p/psycopg2_binary.egg-info/PKG-INFO
writing dependency_links to /tmp/pip-pip-egg-info-qc0tg_5p/psycopg2_binary.egg-info/dependency_links.txt
writing top-level names to /tmp/pip-pip-egg-info-qc0tg_5p/psycopg2_binary.egg-info/top_level.txt
writing manifest file '/tmp/pip-pip-egg-info-qc0tg_5p/psycopg2_binary.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.
This is a known issue. Use the binary version instead:
pip install psycopg2-binary
EDIT:
You dont have 'pg_config' which is part of libpq-dev on Ubuntu. Install it with sudo apt-get install libpq-dev and try abgain.
Before starting the binary installation, export PATH like below:
export PATH=$PATH:/usr/pgsql-12/bin/
Note: Change 12 to your current PostgreSQL version.

couldn't install psycopg2 for a FastAPI project on macOs 10.13.6 : python setup.py egg_info did not run successfully

I tried to install psycopg2 with the command line :
pip install psycopg2
and this is what I get
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]
/Library/Frameworks/Python.framework/Versions/3.10/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/lx/rssnrrbj15jcz8pj88rr89f00000gn/T/pip-pip-egg-info-lpapm88u/psycopg2.egg-info
writing /private/var/folders/lx/rssnrrbj15jcz8pj88rr89f00000gn/T/pip-pip-egg-info-lpapm88u/psycopg2.egg-info/PKG-INFO
writing dependency_links to /private/var/folders/lx/rssnrrbj15jcz8pj88rr89f00000gn/T/pip-pip-egg-info-lpapm88u/psycopg2.egg-info/dependency_links.txt
writing top-level names to /private/var/folders/lx/rssnrrbj15jcz8pj88rr89f00000gn/T/pip-pip-egg-info-lpapm88u/psycopg2.egg-info/top_level.txt
writing manifest file '/private/var/folders/lx/rssnrrbj15jcz8pj88rr89f00000gn/T/pip-pip-egg-info-lpapm88u/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.
then I tried to download the package from the official web site and put in the PATH:
/Users/t/PycharmProjects/API/venv/lib/python3.10/site-packages
(Im using a virtual environement) but I get No module named 'psycopg2'
After reading some similar questions on Stackoverflow here is the solution that worked for me.
First, install Homebrew in case you don't already have it installed
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
then install postgresql :
brew install postgresql
finally use the pip command to install psycpg2 :
pip install psycopg2
sudo apt-get install libpq-dev
it is helped me

python-pushover error on Vercel deployment

I'm trying to deploy a Flask app to Vercel and get this error, which I believe is because of the python-pushover package.
Here is the error log which gets generated after I run vercel --prod on the terminal.
[01:19:33.416] Downloading 523 deployment files...
[01:19:42.856] Looking up build cache...
[01:19:43.125] Build Cache not found
[01:19:43.439] Running "vercel build"
[01:19:44.052] Vercel CLI 25.1.1-canary.7 build (beta) — https://vercel.com/feedback
[01:19:44.211] WARN! Due to `builds` existing in your configuration file, the Build and Development Settings defined in your Project Settings will not apply. Learn More: https://vercel.link/unused-build-settings
[01:19:44.350] Installing required dependencies...
[01:19:48.362] Failed to run "pip3.9 install --disable-pip-version-check --target . --upgrade -r /vercel/path1/requirements.txt"
[01:19:48.424] Error! Command failed: pip3.9 install --disable-pip-version-check --target . --upgrade -r /vercel/path1/requirements.txt
[01:19:48.424] error: subprocess-exited-with-error
[01:19:48.424]
[01:19:48.424] × python setup.py egg_info did not run successfully.
[01:19:48.425] │ exit code: 1
[01:19:48.425] ╰─> [1 lines of output]
[01:19:48.425] error in python-pushover setup command: use_2to3 is invalid.
[01:19:48.425] [end of output]
[01:19:48.425]
[01:19:48.425] note: This error originates from a subprocess, and is likely not a problem with pip.
[01:19:48.425] error: metadata-generation-failed
[01:19:48.425]
[01:19:48.425] × Encountered error while generating package metadata.
[01:19:48.426] ╰─> See above for output.
[01:19:48.426]
[01:19:48.426] note: This is an issue with the package mentioned above, not pip.
[01:19:48.426] hint: See above for details.
[01:19:48.426]
[01:19:48.428] Collecting python-pushover==0.4
[01:19:48.428] Downloading python-pushover-0.4.tar.gz (19 kB)
[01:19:48.428] Preparing metadata (setup.py): started
[01:19:48.428] Preparing metadata (setup.py): finished with status 'error'
[01:19:48.428]
[01:19:48.535] Error: Command "vercel build" exited with 1
I have python3.9 installed in the Pipenv environment.
Has anyone encountered this error before and can provide a solution?
Thanks!
Maybe, You have to check version is support by vercel. I had a similar error, I can solve it fist by checking if I using the venv in python then check if it update.
On Windows the recommended command is:
python -m pip install --upgrade pip

when installing airflow, it occurs: subprocess-exited-with-error

os: centos7.6
python 3.8
occur error:
Collecting airflow
Using cached airflow-0.6.tar.gz (1.2 kB)
Preparing metadata (setup.py) ... error
error: subprocess-exited-with-error
× python setup.py egg_info did not run successfully.
│ exit code: 1
╰─> [1 lines of output]
ERROR: Can not execute setup.py since setuptools is not available in the build environment.
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed
maybe this help
python -m pip uninstall setuptools
pip install setuptools
pip install airflow
This is simply saying the build tool setup.py fails to build from source.
I am not so technical in the aspect of building from source, so I can't tell you exactly what to do with your .tar.gz file to make it all right.
If you have pip installed on the machine (which I assume you do), then simply type:
pip install apache-airflow
The long version:
python3 -m pip install apache-airflow
If you intend to use celery together with Apache Airflow, I suggest:
python3 -m pip install apache-airflow[celery] for full installation.
Refer to the documentation of Apache Airflow for more info.

Error in pip install transformers: Building wheel for tokenizers (pyproject.toml): finished with status 'error'

I'm building a docker image on cloud server via the following docker file:
# base image
FROM python:3
# add python file to working directory
ADD ./ /
# install and cache dependencies
RUN pip install --upgrade pip
RUN pip install RUST
RUN pip install transformers
RUN pip install torch
RUN pip install slack_sdk
RUN pip install slack_bolt
RUN pip install pandas
RUN pip install gensim
RUN pip install nltk
RUN pip install psycopg2
RUN pip install openpyxl
......
When installing the transformers package, the following error occurs:
STEP 5: RUN pip install transformers
Collecting transformers
Downloading transformers-4.15.0-py3-none-any.whl (3.4 MB)
Collecting filelock
......
Downloading click-8.0.3-py3-none-any.whl (97 kB)
Building wheels for collected packages: tokenizers
Building wheel for tokenizers (pyproject.toml): started
ERROR: Command errored out with exit status 1:
command: /usr/local/bin/python /usr/local/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py build_wheel /tmp/tmp_3y7hw5q
cwd: /tmp/pip-install-bsy5f4da/tokenizers_e09b9f903acd40f0af4a997fe1d8fdb4
Complete output (50 lines):
running bdist_wheel
......
copying py_src/tokenizers/trainers/__init__.pyi -> build/lib.linux-x86_64-3.10/tokenizers/trainers
copying py_src/tokenizers/tools/visualizer-styles.css -> build/lib.linux-x86_64-3.10/tokenizers/tools
running build_ext
error: can't find Rust compiler
If you are using an outdated pip version, it is possible a prebuilt wheel is available for this package but pip is not able to install from it. Installing from the wheel would avoid the need for a Rust compiler.
To update pip, run:
pip install --upgrade pip
and then retry package installation.
If you did intend to build this package from source, try installing a Rust compiler from your system package manager and ensure it is on the PATH during installation. Alternatively, rustup (available at https://rustup.rs) is the recommended way to download and update the Rust compiler toolchain.
----------------------------------------
ERROR: Failed building wheel for tokenizers
ERROR: Could not build wheels for tokenizers, which is required to install pyproject.toml-based projects
Building wheel for tokenizers (pyproject.toml): finished with status 'error'
Failed to build tokenizers
subprocess exited with status 1
subprocess exited with status 1
error building at STEP "RUN pip install transformers": exit status 1
time="2022-01-18T07:24:56Z" level=error msg="exit status 1"
Dockerfile build failed - exit status 1exit status 1
I'm not very sure about what's happening here. Can anyone help me? Thanks in advance.
The logs say
error: can't find Rust compiler
You need to install a rust compiler. See https://www.rust-lang.org/tools/install. You can modify the installation instructions for a docker image like this (from https://stackoverflow.com/a/58169817/5666087):
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"
Just use a clean python=3.8 environment and try again.

Categories

Resources