How shoud I fix ERROR with pip install psycopg2==2.7.*? - django

I am trying to put my app that I created on server www using heroku. But when I put to my terminal on Ubuntu pip install psycopg2==2.7.*, I get this error:
ERROR: Command errored out with exit status 1:
command: /home/marcin/Python/learning_log/ll_env/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-c67buptz/psycopg2/setup.py'"'"'; __file__='"'"'/tmp/pip-install-c67buptz/psycopg2/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-install-c67buptz/psycopg2/pip-egg-info
cwd: /tmp/pip-install-c67buptz/psycopg2/
Complete output (28 lines):
running egg_info
creating /tmp/pip-install-c67buptz/psycopg2/pip-egg-info/psycopg2.egg-info
writing /tmp/pip-install-c67buptz/psycopg2/pip-egg-info/psycopg2.egg-info/PKG-INFO
writing dependency_links to /tmp/pip-install-c67buptz/psycopg2/pip-egg-info/psycopg2.egg-info/dependency_links.txt
writing top-level names to /tmp/pip-install-c67buptz/psycopg2/pip-egg-info/psycopg2.egg-info/top_level.txt
writing manifest file '/tmp/pip-install-c67buptz/psycopg2/pip-egg-info/psycopg2.egg-info/SOURCES.txt'
/home/marcin/Python/learning_log/ll_env/lib/python3.8/site-packages/setuptools/config/setupcfg.py:508: SetuptoolsDeprecationWarning: The license_file parameter is deprecated, use license_files instead.
warnings.warn(msg, warning_class)
/home/marcin/Python/learning_log/ll_env/lib/python3.8/site-packages/setuptools/command/egg_info.py:643: SetuptoolsDeprecationWarning: Custom 'build_py' does not implement 'get_data_files_without_manifest'.
Please extend command classes from setuptools instead of distutils.
warnings.warn(
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
<http://initd.org/psycopg/docs/install.html>).
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
What should I do?

You need some dependencies check this answer
https://stackoverflow.com/a/46877364/15208727
sudo apt install libpq-dev python3-dev

You should install pscopg2-binary and the push to heroku
pip install psycopg2-binary or pipenv install psycopg2-binary depending on your virtualenv

Related

Errow while working with django, psycopg file shifting to mac (I WOULD ANSWER MYSELF, IT MAY HELP SOMEONE) [duplicate]

This question already has answers here:
Error Installing Psycopg2 on MacOS 10.9.5
(26 answers)
Closed 6 months ago.
I recently shifted to MAC M2 MONTEREY & one project involved django & my dev env from older system isn't setup here. I got error while installing "psycopg" like this:
Using cached psycopg2-2.8.5.tar.gz (380 kB)
ERROR: Command errored out with exit status 1:
command: /opt/homebrew/opt/python#3.9/bin/python3.9 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/m5/vhnyyjg16gd352x6wdhpjysh0000gn/T/pip-install-9wiqe2nr/psycopg2_97efcf6747c249769acdc8430ba4238f/setup.py'"'"'; __file__='"'"'/private/var/folders/m5/vhnyyjg16gd352x6wdhpjysh0000gn/T/pip-install-9wiqe2nr/psycopg2_97efcf6747c249769acdc8430ba4238f/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /private/var/folders/m5/vhnyyjg16gd352x6wdhpjysh0000gn/T/pip-pip-egg-info-ap2am61r
cwd: /private/var/folders/m5/vhnyyjg16gd352x6wdhpjysh0000gn/T/pip-install-9wiqe2nr/psycopg2_97efcf6747c249769acdc8430ba4238f/
Complete output (23 lines):
running egg_info
creating /private/var/folders/m5/vhnyyjg16gd352x6wdhpjysh0000gn/T/pip-pip-egg-info-ap2am61r/psycopg2.egg-info
writing /private/var/folders/m5/vhnyyjg16gd352x6wdhpjysh0000gn/T/pip-pip-egg-info-ap2am61r/psycopg2.egg-info/PKG-INFO
writing dependency_links to /private/var/folders/m5/vhnyyjg16gd352x6wdhpjysh0000gn/T/pip-pip-egg-info-ap2am61r/psycopg2.egg-info/dependency_links.txt
writing top-level names to /private/var/folders/m5/vhnyyjg16gd352x6wdhpjysh0000gn/T/pip-pip-egg-info-ap2am61r/psycopg2.egg-info/top_level.txt
writing manifest file '/private/var/folders/m5/vhnyyjg16gd352x6wdhpjysh0000gn/T/pip-pip-egg-info-ap2am61r/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>).
==============================================================================
Its beginning of the error, After that its tried to install each previous version of Psycopg
==============================================================================
Searching out for solution, a few things helped me out so here's the answer from my side thinking it may help someone else :)
I was using virtual environment for python for the project.
Solution steps:
upgrade pip3 to latest version
upgrade setup tools with pip3 install --upgrade setuptools, check the version with pip list
Also try installing "postgres" with brew install postgres on the system not in the virtual env of that project (if you're using one) & you can't add it in requirements.txt (INCASE OF AN AUTOMATED DEPLOYMENT) instead you have to then create a bash script which installs OS dependencies first & then the project dependencies with pip3 install -r requirements.txt.
This worked for me.

Error while attempting to pip install psycopg2==2.7.*

I'm trying to run the package, pip install psycopg2==2.7.* ,on my PyCharm terminal so I can deploy my site but I get the message that appears below
Collecting psycopg2
Using cached https://files.pythonhosted.org/packages/a8/8f/1c5690eebf148d1d1554fc00ccf9101e134636553dbb75bdfef4f85d7647/psycopg2-2.8.5.tar.gz
ERROR: Command errored out with exit status 1:
command: /Users/applecare/PycharmProjects/learning_log/11_env/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/w6/sqx_mjh176x08sjppl82f1l80000gn/T/pip-install-8j8wbzsu/psycopg2/setup.py'"'"'; __file__='"'"'/private/var/folders/w6/sqx_mjh176x08sjppl82f1l80000gn/T/pip-install-8j8wbzsu/psycopg2/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base pip-egg-info
cwd: /private/var/folders/w6/sqx_mjh176x08sjppl82f1l80000gn/T/pip-install-8j8wbzsu/psycopg2/
Complete output (23 lines):
running egg_info
creating pip-egg-info/psycopg2.egg-info
writing pip-egg-info/psycopg2.egg-info/PKG-INFO
writing dependency_links to pip-egg-info/psycopg2.egg-info/dependency_links.txt
writing top-level names to pip-egg-info/psycopg2.egg-info/top_level.txt
writing manifest file 'pip-egg-info/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>).
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
WARNING: You are using pip version 19.2.3, however version 20.2.2 is available.
You should consider upgrading via the '`pip install --upgrade pip`' command.
If you are on Linux, you will need to install PostgreSQL to run your database and then to connect the clients to your PostgreSQL database you will need other packages like libpq-dev, libpq5.
You can install the above packages with the below commands.
sudo apt-get install postgresql
sudo apt-get install libpq5
sudo apt-get install libpq-dev
So if you’re on Mac, I can think of two ways:
pip install psycopg2-binary
Install PostgreSQL with brew or the excellent postgre.app and point the path to pg_config binary (this is actually the error you’re getting)
On Mac I did brew install postgresql and it did the trick for me

Django: ERROR: python setup.py egg_info Check the logs for full command output

I am newbie as developer and have developped a first project in Django
I try to deploy my project in a test server (Ubuntu 18.04.1 LTS (GNU/Linux 4.15.0-88-generic x86_64)) prepared by a sys admin in my team
Each time I try to install dependancies (pip install -r requirements.txt) it fail with the error below:
ERROR: Command errored out with exit status 1:
command: /home/test/envs/envTbm/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-1uqfxt7j/psycopg2/setup.py'"'"'; __file__='"'"'/tmp/pip-install-1uqfxt7j/psycopg2/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-install-1uqfxt7j/psycopg2/pip-egg-info
cwd: /tmp/pip-install-1uqfxt7j/psycopg2/
Complete output (7 lines):
running egg_info
creating /tmp/pip-install-1uqfxt7j/psycopg2/pip-egg-info/psycopg2.egg-info
writing /tmp/pip-install-1uqfxt7j/psycopg2/pip-egg-info/psycopg2.egg-info/PKG-INFO
writing dependency_links to /tmp/pip-install-1uqfxt7j/psycopg2/pip-egg-info/psycopg2.egg-info/dependency_links.txt
writing top-level names to /tmp/pip-install-1uqfxt7j/psycopg2/pip-egg-info/psycopg2.egg-info/top_level.txt
writing manifest file '/tmp/pip-install-1uqfxt7j/psycopg2/pip-egg-info/psycopg2.egg-info/SOURCES.txt'
Error: b'You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application.\n'
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
I did not understand what could be the problem...

error: invalid command 'bdist_wheel'

On a RHEL machine
I have some old Django projects that I'm moving to a new server, these were written for Python2.6, Django1.4.3
I've installed python2.7, created the virtualenvs in my home directory, adjusted paths and references to the Python version.
I created a virtualenv for Python2.7:
virtualenv -p python2.7 ~/.virtualenvs/my_site/
When I activate the virtualenv and then cd into the web site directory and run
pip install -r requirements.txt
after successfully fetching all the libs, the following error is displayed for every line in requirements.txt:
Building wheels for collected packages: MySQL-python, Pillow...etc
Running setup.py bdist_wheel for MySQL-python ... error
Complete output from command /home/my_user/.virtualenvs/my_site/bin/python2.7 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-96k9a4/MySQL-python/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/pip-wheel-ngSbQU --python-tag cp27:
usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
or: -c --help [cmd1 cmd2 ...]
or: -c --help-commands
or: -c cmd --help
error: invalid command 'bdist_wheel'
I've found many other similar questions on stackexchange and other sites, and tried the fixes but no luck!
Why can I not create a wheel in python?
Why is python setup.py saying invalid command 'bdist_wheel' on Travis CI?
Can't build wheel - error: invalid command 'bdist_wheel'
I have pip 10.0.1
wheel IS installed (through pip install wheel), I've also run the following in my virtual env:
pip install --upgrade pip ('Requirement already up-to-date')
pip install setuptools --upgrade ('Requirement already up-to-date')
python setup.py bdist_wheel ('error: invalid command 'bdist_wheel'')
What else can I look at to fix this?
Not sure why, but uninstalling wheel fixed it
I uninstalled wheel with a view to reinstalling it, but it worked without reinstalling.
pip uninstall wheel

"error: command 'x86_64-linux-gnu-gcc' failed with exit status 1" in virtualenv

Environment: Linux Mint 17 Cinnamon.
This error is displayed:
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
when attempting the following in a virtualenv:
pip install lxml
pip install pillow
pip install pycrypto
pip install pymongo (fails but still shows in pip freeze)
There are several solutions here that recommend installing python2.7-dev:
Installing Pillow error: Setup script exited with error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
Installing lxml in virtualenv via pip install error: command 'x86_64-linux-gnu-gcc' failed
Pillow installation error: command 'gcc' failed with exit status 1
fatal error: Python.h: No such file or directory
I am confused by this recommendation however because it is my understanding that using something like:
sudo apt-get install python2.7-dev
would add this to the main *system* instance of Python, rather that the one in virtualenv. (see - https://unix.stackexchange.com/a/56392/92486)
Can I add python2.7-dev just to the virtualenv version of Python?
Most of the time these are dependency-issues.
Following the stack-trace of the gcc compiler one can see the missing files. Sometimes installing the Python development packages is not enough.
For example:
I tried to do pip install requests[security] in my virtualenv foo. This is the result that the pip-installer gave me.
Failed building wheel for cryptography
Running setup.py bdist_wheel for cffi
Stored in directory: /root/.cache/pip/wheels/99/e7/9a/68b1c8ca6f6f92b5feebd4d9434f50712b84f6a66d1285ea21
Successfully built cffi
Failed to build cryptography
Installing collected packages: cffi, cryptography, pyOpenSSL, ndg-httpsclient, requests
Running setup.py install for cryptography
Complete output from command /opt/foo/django-cms-virtualenv/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip-build-eZaLAG/cryptography/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-BwgYTp-record/install-record.txt --single-version-externally-managed --compile --install-headers /opt/foo/django-cms-virtualenv/include/site/python2.7/cryptography:
running install
running build
running build_py
running egg_info
writing requirements to src/cryptography.egg-info/requires.txt
writing src/cryptography.egg-info/PKG-INFO
writing top-level names to src/cryptography.egg-info/top_level.txt
writing dependency_links to src/cryptography.egg-info/dependency_links.txt
writing entry points to src/cryptography.egg-info/entry_points.txt
warning: manifest_maker: standard file '-c' not found
reading manifest file 'src/cryptography.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
no previously-included directories found matching 'docs/_build'
warning: no previously-included files matching '*' found under directory 'vectors'
writing manifest file 'src/cryptography.egg-info/SOURCES.txt'
running build_ext
building '_Cryptography_cffi_a269d620xd5c405b7' extension
x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c src/cryptography/hazmat/bindings/__pycache__/_Cryptography_cffi_a269d620xd5c405b7.c -o build/temp.linux-x86_64-2.7/src/cryptography/hazmat/bindings/__pycache__/_Cryptography_cffi_a269d620xd5c405b7.o
src/cryptography/hazmat/bindings/__pycache__/_Cryptography_cffi_a269d620xd5c405b7.c:217:25: fatal error: openssl/aes.h: Datei oder Verzeichnis nicht gefunden
#include <openssl/aes.h>
^
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
The important part is the: #include <openssl/aes.h>
The compiler makes pretty clear that it is demanding this file - but it is not there in the filesystem.
Knowing that, the only thing left to do is: install the needed libraries!
Find out which package is needed for your distribution:
e.g. for Ubuntu you can go to The Ubuntu Package Search Site and enter the missing file you are looking for. In this case "aes.h"
Install the needed packages using your distributions package management tool:
e.g. for Ubuntu:
aptitude install libssl-dev
Retry with pip in your virtualenv:
pip install requests[security]
I installed python2.7-dev via Synaptic Package Manager in Linux Mint 17.
I could then accomplish the following in virtualenv:
pip install pillow
pip install pycrypto
And then I installed libxml2-dev and libxslt1-dev via Synaptic and could accomplish the following:
pip install lxml
I also did this so that the pymongo install didn't have any errors:
pip uninstall pymongo
pip install pymongo # i defined the version i needed ie pip install pymongo==2.6.2
I'm still confused how this fixes the problem, because I thought virtualenv was an isolated environment. Any clarification about this appreciated.
Work for me :
Just install python2.7-dev first
sudo apt-get install python2.7-dev
In Ubuntu 16.04.1 this worked for me:
sudo apt-get install libxml2-dev libxslt1-dev python-dev
For me the installation of lxml was failing on compilation. I followed the instructions for installation of lxml and reduced the compiler optimizations:
sudo CFLAGS="-O0" pip install lxml
After doing this, the compile of lxml succeeded.
This can be a problem in the pip. To solve, try:
sudo apt-get remove python-pip
To install pip, securely download get-pip.py.
https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py
The cffi library needs libffi-dev:
sudo apt-get install libffi libffi-dev
Easiest way is:
sudo apt-get build-dep python-imaging
and then
pip install pillow
This works for me, 12.04, python2.7.6 for package lxml
sudo pip install libxml2 libxml2-dev libxslt1-dev
sudo pip install lxml