Reputation: 433
Very much brand new to this and trying to learn from a tut, I'm trying to install dependencies for a Flask build and getting an error on terminal
I have the following to install
pipenv install flask flask-sqlalchemy psycopg2 flask-migrate flask-script marshmallow flask-bcrypt pyjwt
I have check Python, PostSQL, pipenv are installed and get the following error
An error occurred while installing psycopg2==2.8.1 --hash=sha256:3648afc2b4828a6e00d516d2d09a260edd2c1e3de1e0d41d99c5ab004a73d180 --hash=sha256:5329b4530e31f58e0eafc55e26bbef684509bcc3be41604e45c0b98c297dc722 --hash=sha256:7c1ae1669d11105a002f804bebd7432f8dc7473459aa405164c6b44a922decd5 --hash=sha256:8af13498e32a00d0a66e43b7491c15231b27ab964ee4d2277a4a2dbadfb2c482 --hash=sha256:9d5489867bd5f6d6c6191a4debd8de9a5c03a9608cce3f4d7133e29e6bd4ec27 --hash=sha256:a17bfc9faffcca0ad9360c1ad97ab61ede583aa954715e8e436ffd80046661ff --hash=sha256:b4a475ce87eabc0607e068a3c704d0aa0820237ed78d493b8e2d880eb73cd7fe --hash=sha256:c49d66e97affdc80d084b3b363f09f17db621418f0b8e0524b06c54959e2094d --hash=sha256:d13fbc3d533656cfdf094e13c1b0f40917b72813755ba780971ba0ce04280ac4 --hash=sha256:e1e4fe6e8ab9f9c7d28514d007f623999d2dd6b5b81069dd4f9d30dbdd6f7069 --hash=sha256:e67d60cb1a32f5fd8fcea935cf9efb1d1c26f96203b0ca2ae98c4c40ef8d8eac! Will try again.
Upvotes: 9
Views: 15087
Reputation: 2526
I recently experienced the same problem on a macOS 10.15 (Catalina). In my case the problem was related to a previous upgrade of the OpenSSL library, which had installed the new version to a non-standard location in my system. Not being able to locate the SSL libraries, the psycopg2 compilation task complained with a ton of errors.
The solution in this and similar cases is to tell the compiler where the include files and libraries are located, which can be done by properly setting the LDFLAGS and CPPFLAGS environment variables. For example:
> export LDFLAGS="-L/usr/local/opt/openssl/lib"
> export CPPFLAGS="-I/usr/local/opt/openssl/include"
If you can't find OpenSSL in your system, then you may have to install the library first via brew install openssl
(macOS), apt install libssl-dev
(Linux Ubuntu) or whatever procedure is most convenient for your OS.
Once the libraries are installed and the environment is properly set, pipenv should eventually be able to install psycopg2:
> pipenv install psycopg2
There are other solutions as suggested in other answers in this thread, but be aware that some of them can bring problems even if they work. For example, we can try to install psycopg2-binary instead of psycopg2 via:
> pipenv install psycopg2-binary
Note though that this solution is only valid for a development environment and should not be employed in production. Indeed from the psycopg2 home page we read:
The binary package is a practical choice for development and testing but in production it is advised to use the package built from sources.
Installing psycopg2-binary via pip like in:
pipenv run pip install psycopg2-binary
is possibly even worse, because when we use pipenv we are ensured of a correct recording of all the dependencies. But if we delegate the installation task to pip like in the command above, we won't get anything recorded in the "Pipfile".
.
Upvotes: 0
Reputation: 179
U can use postgres. It is a high-value abstraction over psycopg2. And it use psycopg2-binary. After pipenv install postgres You will see next reqs in pip list:
postgres 3.0.0
psycopg2-binary 2.8.4
psycopg2-pool 1.1
The binary package is a practical choice for development and testing but in production it is advised to use the package built from sources. So don't use only psycopg2-binary in production.
# project/settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'postgres',
'USER': 'postgres',
'PASSWORD': 'postgres',
'HOST': 'db',
'PORT': 5432
}
}
EXTRA: You can olso use psycopg2 version > 2.7 with pipenv on Windows with no problems.
PS D:\> pipenv shell
Creating a virtualenv for this project…
Pipfile: D:\Pipfile
Using c:\python\python37\python.exe (3.7.6) to create virtualenv…
[=== ] Creating virtual environment...created virtual environment CPython3.7.6.final.0-64 in 2093ms
creator CPython3Windows(dest=D:\-_SHv_4lM, clear=False, global=False)
seeder FromAppData(download=False, pip=latest, setuptools=latest, wheel=latest, via=copy, app_data_dir=C:\Users\parfeniukink\AppData\Local\Temp\tmpnwrfdufn\seed-app-data\v1)
activators BashActivator,BatchActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator
Successfully created virtual environment!
Virtualenv location: D:-_SHv_4lM
Creating a Pipfile for this project…
Launching subshell in virtual environment…
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
Try the new cross-platform PowerShell https://aka.ms/pscore6
PS D:\> pipenv install psycopg2
Installing psycopg2…
Adding psycopg2 to Pipfile's [packages]…
Installation Succeeded
Pipfile.lock not found, creating…
Locking [dev-packages] dependencies…
Locking [packages] dependencies…
Success!
Updated Pipfile.lock (59b6f6)!
Installing dependencies from Pipfile.lock (59b6f6)…
================================ 1/1 - 00:00:00
PS D:\> pip list
Package Version
---------- -------
pip 20.0.2
psycopg2 2.8.4
setuptools 45.2.0
wheel 0.34.2
PS D:\>
Upvotes: 0
Reputation: 199
Just exporting some flags worked for me:
export LDFLAGS="-L/usr/local/opt/openssl/lib" export CPPFLAGS="-I/usr/local/opt/openssl/include"
from the official thread: https://github.com/psycopg/psycopg2/issues/997
Upvotes: 5
Reputation: 5992
I had to resort to piping in run pip
pipenv run pip install psycopg2-binary
Upvotes: 1
Reputation: 71
If you see Error like the following, then you should install libpq-dev
sudo apt-get install libpq-dev
Error: b'You need to install postgresql-server-dev-NN 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.']
Upvotes: 2
Reputation: 1448
You need to install previously the following compiler:
sudo apt-get install libpq-dev
Upvotes: 12