I am having trouble installing psycopg2. I get the following error when I try to pip install psycopg2:
Error: pg_config executable not found.
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'.
----------------------------------------
Command python setup.py egg_info failed with error code 1 in /tmp/pip-build/psycopg2
But the problem is pg_config is actually in my PATH; it runs without any problem:
$ which pg_config
/usr/pgsql-9.1/bin/pg_config
I tried adding the pg_config path to the setup.cfg file and building it using the source files I downloaded from their website (http://initd.org/psycopg/) and I get the following error message!
Error: Unable to find 'pg_config' file in '/usr/pgsql-9.1/bin/'
But it is actually THERE!!!
I am baffled by these errors. Can anyone help please?
By the way, I sudo all the commands. Also I am on RHEL 5.5.
pg_config is in postgresql-devel (libpq-dev in Debian/Ubuntu, libpq-devel on Centos/Fedora/Cygwin/Babun.)
On Mac OS X, I solved it using the homebrew package manager
brew install postgresql
Have you installed python-dev?
If you already have, try also installing libpq-dev
sudo apt-get install libpq-dev python-dev
From the article: How to install psycopg2 under virtualenv
Also on OSX. Installed Postgress.app from http://postgresapp.com/ but had the same issue.
I found pg_config in that app's contents and added the dir to $PATH.
It was at /Applications/Postgres.app/Contents/Versions/latest/bin. So this worked: export PATH="/Applications/Postgres.app/Contents/Versions/latest/bin:$PATH".
You can install pre-compiled binaries on any platform with pip or conda:
python -m pip install psycopg2-binary
or
conda install psycopg2
Please be advised that the psycopg2-binary pypi page recommends building from source in production:
The binary package is a practical choice for development and testing but in production it is advised to use the package built from sources
To use the package built from sources, use python -m pip install psycopg2. That process will require several dependencies (documentation) (emphasis mine):
A C compiler.
The Python header files. They are usually installed in a package such as python-dev. A message such as error: Python.h: No such file or directory is an indication that the Python headers are missing.
The libpq header files. They are usually installed in a package such as libpq-dev. If you get an error: libpq-fe.h: No such file or directory you are missing them.
The pg_config program: it is usually installed by the libpq-dev package but sometimes it is not in a PATH directory. Having it in the PATH greatly streamlines the installation, so try running pg_config --version: if it returns an error or an unexpected version number then locate the directory containing the pg_config shipped with the right libpq version (usually /usr/lib/postgresql/X.Y/bin/) and add it to the PATH:
$ export PATH=/usr/lib/postgresql/X.Y/bin/:$PATH
You only need pg_config to compile psycopg2, not for its regular usage.
Once everything is in place it’s just a matter of running the standard:
$ pip install psycopg2
or, from the directory containing the source code:
$ python setup.py build
$ python setup.py install
For ubuntu users, this is the solution:
sudo apt install libpq-dev
It worked for me.
On alpine, the library containing pg_config is postgresql-dev. To install, run:
apk add postgresql-dev
This is what worked for me on CentOS, first install:
sudo yum install postgresql postgresql-devel python-devel
On Ubuntu just use the equivilent apt-get packages.
sudo apt-get install postgresql postgresql-dev python-dev
And now include the path to your postgresql binary dir with you pip install, this should work for either Debain or RHEL based Linux:
sudo PATH=$PATH:/usr/pgsql-9.3/bin/ pip install psycopg2
Make sure to include the correct path. Thats all :)
You have to install libpq-dev/postgresql-libs, which is the header files and static library for compiling C programs to link with the libpq library in order to communicate with a PostgreSQL database backend.
On Arch this will run:
$ sudo pacman -S postgresql-libs
On Debian and Ubuntu:
$ sudo apt-get install libpq-dev
On Mac OS X:
$ brew install postgresql
On Red Hat/CentOS/Fedora:
$ sudo yum install postgresql-devel
apt-get build-dep python-psycopg2
Just to sum up, I also faced exactly same problem. After reading a lot of stackoverflow posts and online blogs, the final solution which worked for me is this:
1) PostgreSQL(development or any stable version) should be installed before installing psycopg2.
2) The pg_config file (this file normally resides in the bin folder of the PostgreSQL installation folder) PATH had to be explicitly setup before installing psycopg2. In my case, the installation PATH for PostgreSQL is:
/opt/local/lib/postgresql91/
so in order to explicitly set the PATH of pg_config file, I entered following command in my terminal:
PATH=$PATH:/opt/local/lib/postgresql91/bin/
This command ensures that when you try to pip install psycopg2, it would find the PATH to pg_config automatically this time.
I have also posted a full error with trace and its solution on my blog which you may want to refer. Its for Mac OS X but the pg_config PATH problem is generic and applicable to Linux also.
You should add python requirements used in Postgres on Ubuntu. Run:
sudo apt-get install libpq-dev python-dev
sudo apt-get install libpq-dev works for me on Ubuntu 15.4
I had this issue because I didn't had a postgres install. If you have brew install run
brew install postgresql
This should fix the issue.
For those running OS X, this solution worked for me:
1) Install Postgres.app:
http://www.postgresql.org/download/macosx/
2) Then open the Terminal and run this command, replacing where it says {{version}} with the Postgres version number:
export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/{{version}}/bin
e.g.
export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.4/bin
On Linux Mint sudo apt-get install libpq-dev worked for me.
UPDATE /etc/yum.repos.d/CentOS-Base.repo, [base] and [updates] sections
ADD exclude=postgresql*
curl -O http://yum.postgresql.org/9.1/redhat/rhel-6-i386/pgdg-centos91-9.1-4.noarch.rpmr
rpm -ivh pgdg-centos91-9.1-4.noarch.rpm
yum install postgresql
yum install postgresql-devel
PATH=$PATH:/usr/pgsql-9.1/bin/
pip install psycopg2
Simply run the following:
sudo apt install libpq-dev
Fixed the issue for me
Try to add it to PATH:
PATH=$PATH:/usr/pgsql-9.1/bin/ ./pip install psycopg2
Ali's solution worked for me but I was having trouble finding the bin folder location. A quick way to find the path on Mac OS X is to open psql (there's a quick link in the top menu bar). This will open a separate terminal window and on the second line the path of your Postgres installation will appear like so:
My-MacBook-Pro:~ Me$ /Applications/Postgres93.app/Contents/MacOS/bin/psql ; exit;
Your pg_config file is in that bin folder. Therefore, before installing psycopg2 set the path of the pg_config file:
PATH=$PATH:/Applications/Postgres93.app/Contents/MacOS/bin/
or for newer version:
PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.3/bin
Then install psycopg2.
I'm going to leave this here for the next unfortunate soul who can't get around this problem despite all the provided solutions. Simply use sudo pip3 install psycopg2-binary
You need to upgrade your pip before installing psycopg2. Use this command
pip install --upgrade pip
On MacOS, the simplest solution will be to symlink the correct binary, that is under the Postgres package.
sudo ln -s /Applications/Postgres.app/Contents/Versions/latest/bin/pg_config /usr/local/bin/pg_config
This is fairly harmless, and all the applications will be able to use it system wide, if required.
On Mac OS X and If you are using Postgres App (http://postgresapp.com/):
export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/latest/bin
No need to specify version of Postgres in this command. It will be always pointed to latest.
and do
pip install psycopg2
P.S: If Changes doesn't reflect you may need to restart the Terminal/Command prompt
Source
Installing python-psycopg2 solved it for me on Arch Linux:
pacman -S python-psycopg2
On Windows,
You may want to install the Windows port of Psycopg, which is recommended in psycopg's documentation.
Just solved the problem in Cent OS 7 by:
export PATH=$PATH:/usr/pgsql-9.5/bin
make sure your PostgreSql version matches the right version above.
This was partly suggested before, adding it here for clarity.
From the documentation at https://www.psycopg.org/docs/install.html.
they suggest running: $ pip install psycopg2-binary
That solved the issue for me.
Here, for OS X completeness: if you install PostgreSQL from MacPorts, pg_config will be in /opt/local/lib/postgresql94/bin/pg_config.
When you installed MacPorts, it already added /opt/local/bin to your PATH.
So, this will fix the problem:
$ sudo ln -s /opt/local/lib/postgresql94/bin/pg_config /opt/local/bin/pg_config
Now pip install psycopg2 will be able to run pg_config without issues.
To those on macOS Catalina using the zsh shell who have also installed the postgres app:
Open your ~/.zshrc file, and add the following line:
export PATH="/Applications/Postgres.app/Contents/Versions/latest/bin:$PATH"
Then close all your terminals, reopen them, and you'll have resolved your problem.
If you don't want to close your terminals, simply enter source ~/.zshrc in whatever terminal you'd like to keep working on.
Related
I am using Python 3.6. When I try to install "modules" using pip3, I face this issue:
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available
For Windows 10
if you want use pip in normal cmd, not only in Anaconda prompt. you need add 3 environment paths.
like the followings:
D:\Anaconda3
D:\Anaconda3\Scripts
D:\Anaconda3\Library\bin
most people only add D:\Anaconda3\Scripts
MAC OS
I had the same problem on Mac OS(Mojave) and solved the problem as mentioned on this link - Openssl issue.
If you do not have Homebrew or don't know what is Homebrew:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Or if you already have Homebrew installed:
brew update && brew upgrade
brew uninstall --ignore-dependencies openssl; brew install https://github.com/tebelorg/Tump/releases/download/v1.0.0/openssl.rb
Update:
Keep in mind, that I had to use --ignore-dependencies flag, because other packages installed that depend on OpenSSL.
Additional if the problem is caused after using pyenv, you can fix it by using:
brew reinstall python
For Debian users, the following may be of use:
sudo apt install libssl-dev libncurses5-dev libsqlite3-dev libreadline-dev libtk8.6 libgdm-dev libdb4o-cil-dev libpcap-dev
Then cd to the folder with the Python 3.X library source code and run:
./configure
make
make install
I'm using Windows 10 and installed Miniconda 3 with Python 3.7.
I solved this error by following this https://github.com/conda/conda/issues/8273
Specifically, I copied the following files from C:\Users\MyUser\Miniconda3\Library\bin to C:\Users\MyUser\Miniconda3\DLLs:
libcrypto-1_1-x64.dll
libcrypto-1_1-x64.pdb
libssl-1_1-x64.dll
libssl-1_1-x64.pdb
For centos 7:
Install openssl:
sudo yum install openssl-devel
now goto python directory were we extracted the python tar,
run below commands
sudo ./configure
sudo make
sudo make install
This will fix the problem in centos...
For future Oracle Linux users trying to solve this, below is what worked for me.
First install missing libs:
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel
readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
Then cd to your Python3.X library and run:
make
make install
macOS, pyenv
In case of your python being an pyenv installed one, where pyenv is installed with homebrew on macOS, there might me a newer version available which fixes this:
$ brew update && brew upgrade pyenv
Then reinstalling the python version:
$ pyenv install 3.7.2
pyenv: /Users/luckydonald/.pyenv/versions/3.7.2 already exists
continue with installation? (y/N)
Note, it is a bit dirty to overwrite the existing python install like that, but in my case it did work out. Probably cleaner to delete it and then recreate it properly.
For Windows 10,windows 7
If pip install is not working on CMD prompt, run it using Anaconda prompt - it works.
https://github.com/pypa/virtualenv/issues/1139
Worked for me.
sudo apt-get install libssl-dev
Use this to enable ssl for pip.
Let me know if someone encounters issues.
Encountered this issue while installing python 3.8 from source on ubuntu. The steps needed to install it successfully alongside the default python 3.7 are summarised below :
sudo apt -y install libssl-dev zlib1g-dev build-essential
wget https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tgz
tar -xf Python-3.8.0.tgz
cd Python-3.8.0/
./configure --enable-optimizations
make
sudo make altinstall
The install instruction for zlib1g-dev and build-essential is redundant, as ubuntu desktop already has these, but was necessary for some of Amazon's EC2 instances. python 3.8.0 is the current release just now, but should be replaced with the latest available.
These instructions are best for keeping python 3.7 as the default for python3, and running python 3.8 in a virtual environment.
Similar to the above solution reinstall the python version with pyenv.
Somehow, I upgraded my openssl which broke the pyenv version python.
pyenv install 3.6.8
python-build: use openssl#1.1 from homebrew
python-build: use readline from homebrew
...
The first line says it relies on the homebrew openssl.
In my case, I reinstalled Python. It solved the problem.
brew reinstall python
For OpenSUSE in the same manner, but a few changes of listed above packages:
zypper install zlib-devel libopenssl-devel ncurses-devel sqlite3-devel readline-devel tk-devel gdbm-devel libpcap-devel xz-devel
Then cd to Python sources dir and
make
make install
or
make
make altinstall
And perhaps
ln -s /usr/local/lib64/python3.6/lib-dynload/ /usr/local/lib/python3.6/lib-dynload
should be executed for OpenSUSE users. See Python 3.7 install not working on openSUSE Leap 42.3
Just try installing through Anaconda prompt
I ran into this issue with Visual Studio Code installing pylint from the VS Code prompt.
I was able to overcome the issue by opening the Anaconda installation directory and running
pip install pylint
Then VS Code was happy, but that did not fix the issue as running
& C:/Users/happy/Anaconda3/python.exe -m pip install -U pylint
pretty much gave the same error so it seems that VS Code is unable to access the python modules.
Note that VS Code picks up the first python env it see when installed, the bottom left of the screen indicates which env is being used. Clicking on that area allows to set the environment. So even if you ran the pip install for an environment VS Code could be looking at a different one.
Best approach was to make sure that VS code had the correct python environment selected and that same environment is in the system PATH (under System Properties --> Advanced --> Environmental Variables)
Under the Path Variable, Edit and browse to the specific Anaconda directory that you want VSCode to use and add to PATH, I needed to Add the following:
C:\Users\happy\Anaconda3\
C:\Users\happy\Anaconda3\Scripts\
C:\Users\happy\Anaconda3\Library\bin\
C:\Users\happy\Anaconda3\Library\mingw-w64\bin\
Your Anaconda installation directory may differ.
One note is that Windows does not have the PATH variable take effect until you restart the terminal. In this case close and re-op VS code. If using a Terminal or PS Shell then close and reopen and check Path to make sure it is included.
The problem probably comes from your installed openssl package version. That was the case for me and I fixed this issue just upgrading it. I'm on Mac OS, using brew :
brew upgrade openssl
If you installed python with brew, this should directly fix the issue with it, as python is dependent on openssl
Newest Python 3.8.4 or higher should able to support https protocol out of box. If you still have old python installation on your pc - either download & install python3 manually, or using Chocolatey:
If you don't have Chocolatey, install it - from here: https://chocolatey.org/docs/installation
You can just copy paste one command line liner and execute it from command prompt with elevated priviledges.
choco install python3
if you don't have python3 installed, or you you have it installed - then:
choco upgrade python3
Notice also that you can use also anaconda distribution, as it has built-in python with https support, but this rather ancient instructions, no need to follow them anymore.
Install anaconda, using command line:
choco install anaconda3
Set environment variables:
set PATH=C:\tools\Anaconda3\Scripts;C:\tools\Anaconda3;C:\tools\Anaconda3\Library\bin;%PATH%
and then run command which failed. In my case it was:
pip install conan
Anaconda uses separate python installation, and pip is also anaconda specific.
As Tokci said, it also works for Windows 7.
"Go with the mouse to the Windows Icon (lower left) and start typing "Anaconda". There should show up some matching entries. Select "Anaconda Prompt". A new command window, named "Anaconda Prompt" will open."
Then pip works.
The following also helped to import xgboost:
https://www.youtube.com/watch?v=05djBSOs1FA
If someone is using Arch Linux OS, I solved the TLS/SSL problem by running this:
sudo pacman -S openssl
Then I could use pip to install the package I needed:
pip install openpyxl
Go to Anaconda prompt and type (if you have python 3.x installed on your engine) :
py -m pip install pymysql
i was having the same issue and this solved my problem. later after doing this you can import pymysql in power shell or any other prompt.
The issue is due to OpenSSL package is missing on your PC.
If pip install openpyxl also gives error.
you can fix this by installing OpenSSL(Win64 OpenSSL v1.1.1g) from below site :
slproweb.com/products/Win32OpenSSL.html
Restart the IDE you are using, for changes to be in effect.
In Windows 10 SQL Server 19 the solution is known.
Copy the following files:
libssl-1_1-x64.dll
libcrypto-1_1-x64.dll
from the folder
C:\Program Files\Microsoft SQL Server\MSSSQL15.MSSQLSERVER\PYTHON_SERVICES\Library\bin
to the folder
C:\Program Files\Microsoft SQL Server\MSSSQL15.MSSQLSERVER\PYTHON_SERVICES\DLLs
Then open a new DOS command shell prompt.
From https://learn.microsoft.com/en-us/sql/machine-learning/troubleshooting/known-issues-for-sql-server-machine-learning-services?view=sql-server-ver15#7-unable-to-install-python-packages-using-pip-after-installing-sql-server-2019-on-windows
Worked for me.
pkg install openssl
Use this to enable ssl.
Currently there is same issue in Anaconda prompt (Anaconda3) on Windows 10. Here is workaround: https://github.com/ContinuumIO/anaconda-issues/issues/10576
Fixed this without having to change anything related to TSL/SSL.
I was trying to see if the same thing was happening to pip, and saw that pip was broken. Did some digging and realized it's probably caused by Homebrew deleted python#2 on February 1st, 2020.
Running brew uninstall python#2 to delete python2 installed by Homebrew.
Destroyed the virtual env created using python3 and created a new one. pip3 installing works fine again.
I am on macOS and I had used brew but what Vaulstein mentioned in his answer didn't cover my case.
I run the following commands to make sure my current python was not installed by brew
brew list | grep python
python
python#2
brew info python
python#3.8: stable 3.8.3 (bottled)
Interpreted, interactive, object-oriented programming language
https://www.python.org/
Not installed
...
So I download the latest 3.8.5 from https://www.python.org/ and when installing it I saw following information
Certificate verification and OpenSSL
This package includes its own private copy of OpenSSL 1.1.1. The
trust certificates in system and user keychains managed by the
Keychain Access application and the security command line utility are not used as defaults by the Python ssl module
After installed 3.8.5 it fixed the problem.
I got into this problem using Ubuntu, pyenv and Python 3.8.1 managed by pyenv. There was actually no way to get pip to work correctly, since every time I tried to install anything, including pip itself, the same error showed up.
Final solution was to install, via pyenv, a newer version, in this case 3.8.6. Apparently, from 3.8.4 Python is prepared to run SSL/TLS out of the box, so everything worked fine.
I simply solved the problem with following command:
brew upgrade python#3.9
SSL is included by default on this version!
In my case I was running into issues with my $PATH on Linux. This can also happen on MacOS.
Check to see if /usr/bin/pip3 install package_name_goes_here works for you. If so then run
which pip3 this will tell you which is the first directory that pip3 is installed in.
If it is something like /usr/local/bin/pip3 which is different from /usr/bin/pip3 then you may need to adjust your $PATH.
Run
echo $PATH and copy the result.
The PATH is simply a colon separated list of directories that contain directories. Bash will always return the first instance of the program that you are attempting to execute. Move all the system directories upfront. Here is a list of some of the system directories:
/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin
If that fails then verify you have openssl installed by running openssl version -a if not then install openssl.
If you've installed anaconda via scoop, and encounter this error while using pip from within a conda environment you can resolve it by...
Adding these to your path
C:\Users\YOUR_USERNAME\scoop\apps\anaconda3\current
C:\Users\YOUR_USERNAME\scoop\apps\anaconda3\current\Scripts
C:\Users\YOUR_USERNAME\scoop\apps\anaconda3\current\Library
C:\Users\YOUR_USERNAME\scoop\apps\anaconda3\current\Library\bin
Installing openssl via scoop
scoop install openssl
And copying the following DLLs from ..\anaconda3\Library\bin to ..\anaconda3\DLLs
References:
https://stackoverflow.com/a/54897379
https://stackoverflow.com/a/60405693
I am having trouble installing psycopg2. I get the following error when I try to pip install psycopg2:
Error: pg_config executable not found.
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'.
----------------------------------------
Command python setup.py egg_info failed with error code 1 in /tmp/pip-build/psycopg2
But the problem is pg_config is actually in my PATH; it runs without any problem:
$ which pg_config
/usr/pgsql-9.1/bin/pg_config
I tried adding the pg_config path to the setup.cfg file and building it using the source files I downloaded from their website (http://initd.org/psycopg/) and I get the following error message!
Error: Unable to find 'pg_config' file in '/usr/pgsql-9.1/bin/'
But it is actually THERE!!!
I am baffled by these errors. Can anyone help please?
By the way, I sudo all the commands. Also I am on RHEL 5.5.
pg_config is in postgresql-devel (libpq-dev in Debian/Ubuntu, libpq-devel on Centos/Fedora/Cygwin/Babun.)
On Mac OS X, I solved it using the homebrew package manager
brew install postgresql
Have you installed python-dev?
If you already have, try also installing libpq-dev
sudo apt-get install libpq-dev python-dev
From the article: How to install psycopg2 under virtualenv
Also on OSX. Installed Postgress.app from http://postgresapp.com/ but had the same issue.
I found pg_config in that app's contents and added the dir to $PATH.
It was at /Applications/Postgres.app/Contents/Versions/latest/bin. So this worked: export PATH="/Applications/Postgres.app/Contents/Versions/latest/bin:$PATH".
You can install pre-compiled binaries on any platform with pip or conda:
python -m pip install psycopg2-binary
or
conda install psycopg2
Please be advised that the psycopg2-binary pypi page recommends building from source in production:
The binary package is a practical choice for development and testing but in production it is advised to use the package built from sources
To use the package built from sources, use python -m pip install psycopg2. That process will require several dependencies (documentation) (emphasis mine):
A C compiler.
The Python header files. They are usually installed in a package such as python-dev. A message such as error: Python.h: No such file or directory is an indication that the Python headers are missing.
The libpq header files. They are usually installed in a package such as libpq-dev. If you get an error: libpq-fe.h: No such file or directory you are missing them.
The pg_config program: it is usually installed by the libpq-dev package but sometimes it is not in a PATH directory. Having it in the PATH greatly streamlines the installation, so try running pg_config --version: if it returns an error or an unexpected version number then locate the directory containing the pg_config shipped with the right libpq version (usually /usr/lib/postgresql/X.Y/bin/) and add it to the PATH:
$ export PATH=/usr/lib/postgresql/X.Y/bin/:$PATH
You only need pg_config to compile psycopg2, not for its regular usage.
Once everything is in place it’s just a matter of running the standard:
$ pip install psycopg2
or, from the directory containing the source code:
$ python setup.py build
$ python setup.py install
For ubuntu users, this is the solution:
sudo apt install libpq-dev
It worked for me.
On alpine, the library containing pg_config is postgresql-dev. To install, run:
apk add postgresql-dev
This is what worked for me on CentOS, first install:
sudo yum install postgresql postgresql-devel python-devel
On Ubuntu just use the equivilent apt-get packages.
sudo apt-get install postgresql postgresql-dev python-dev
And now include the path to your postgresql binary dir with you pip install, this should work for either Debain or RHEL based Linux:
sudo PATH=$PATH:/usr/pgsql-9.3/bin/ pip install psycopg2
Make sure to include the correct path. Thats all :)
You have to install libpq-dev/postgresql-libs, which is the header files and static library for compiling C programs to link with the libpq library in order to communicate with a PostgreSQL database backend.
On Arch this will run:
$ sudo pacman -S postgresql-libs
On Debian and Ubuntu:
$ sudo apt-get install libpq-dev
On Mac OS X:
$ brew install postgresql
On Red Hat/CentOS/Fedora:
$ sudo yum install postgresql-devel
apt-get build-dep python-psycopg2
Just to sum up, I also faced exactly same problem. After reading a lot of stackoverflow posts and online blogs, the final solution which worked for me is this:
1) PostgreSQL(development or any stable version) should be installed before installing psycopg2.
2) The pg_config file (this file normally resides in the bin folder of the PostgreSQL installation folder) PATH had to be explicitly setup before installing psycopg2. In my case, the installation PATH for PostgreSQL is:
/opt/local/lib/postgresql91/
so in order to explicitly set the PATH of pg_config file, I entered following command in my terminal:
PATH=$PATH:/opt/local/lib/postgresql91/bin/
This command ensures that when you try to pip install psycopg2, it would find the PATH to pg_config automatically this time.
I have also posted a full error with trace and its solution on my blog which you may want to refer. Its for Mac OS X but the pg_config PATH problem is generic and applicable to Linux also.
You should add python requirements used in Postgres on Ubuntu. Run:
sudo apt-get install libpq-dev python-dev
sudo apt-get install libpq-dev works for me on Ubuntu 15.4
I had this issue because I didn't had a postgres install. If you have brew install run
brew install postgresql
This should fix the issue.
For those running OS X, this solution worked for me:
1) Install Postgres.app:
http://www.postgresql.org/download/macosx/
2) Then open the Terminal and run this command, replacing where it says {{version}} with the Postgres version number:
export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/{{version}}/bin
e.g.
export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.4/bin
On Linux Mint sudo apt-get install libpq-dev worked for me.
UPDATE /etc/yum.repos.d/CentOS-Base.repo, [base] and [updates] sections
ADD exclude=postgresql*
curl -O http://yum.postgresql.org/9.1/redhat/rhel-6-i386/pgdg-centos91-9.1-4.noarch.rpmr
rpm -ivh pgdg-centos91-9.1-4.noarch.rpm
yum install postgresql
yum install postgresql-devel
PATH=$PATH:/usr/pgsql-9.1/bin/
pip install psycopg2
Simply run the following:
sudo apt install libpq-dev
Fixed the issue for me
Try to add it to PATH:
PATH=$PATH:/usr/pgsql-9.1/bin/ ./pip install psycopg2
Ali's solution worked for me but I was having trouble finding the bin folder location. A quick way to find the path on Mac OS X is to open psql (there's a quick link in the top menu bar). This will open a separate terminal window and on the second line the path of your Postgres installation will appear like so:
My-MacBook-Pro:~ Me$ /Applications/Postgres93.app/Contents/MacOS/bin/psql ; exit;
Your pg_config file is in that bin folder. Therefore, before installing psycopg2 set the path of the pg_config file:
PATH=$PATH:/Applications/Postgres93.app/Contents/MacOS/bin/
or for newer version:
PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.3/bin
Then install psycopg2.
I'm going to leave this here for the next unfortunate soul who can't get around this problem despite all the provided solutions. Simply use sudo pip3 install psycopg2-binary
You need to upgrade your pip before installing psycopg2. Use this command
pip install --upgrade pip
On MacOS, the simplest solution will be to symlink the correct binary, that is under the Postgres package.
sudo ln -s /Applications/Postgres.app/Contents/Versions/latest/bin/pg_config /usr/local/bin/pg_config
This is fairly harmless, and all the applications will be able to use it system wide, if required.
On Mac OS X and If you are using Postgres App (http://postgresapp.com/):
export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/latest/bin
No need to specify version of Postgres in this command. It will be always pointed to latest.
and do
pip install psycopg2
P.S: If Changes doesn't reflect you may need to restart the Terminal/Command prompt
Source
Installing python-psycopg2 solved it for me on Arch Linux:
pacman -S python-psycopg2
On Windows,
You may want to install the Windows port of Psycopg, which is recommended in psycopg's documentation.
Just solved the problem in Cent OS 7 by:
export PATH=$PATH:/usr/pgsql-9.5/bin
make sure your PostgreSql version matches the right version above.
This was partly suggested before, adding it here for clarity.
From the documentation at https://www.psycopg.org/docs/install.html.
they suggest running: $ pip install psycopg2-binary
That solved the issue for me.
Here, for OS X completeness: if you install PostgreSQL from MacPorts, pg_config will be in /opt/local/lib/postgresql94/bin/pg_config.
When you installed MacPorts, it already added /opt/local/bin to your PATH.
So, this will fix the problem:
$ sudo ln -s /opt/local/lib/postgresql94/bin/pg_config /opt/local/bin/pg_config
Now pip install psycopg2 will be able to run pg_config without issues.
To those on macOS Catalina using the zsh shell who have also installed the postgres app:
Open your ~/.zshrc file, and add the following line:
export PATH="/Applications/Postgres.app/Contents/Versions/latest/bin:$PATH"
Then close all your terminals, reopen them, and you'll have resolved your problem.
If you don't want to close your terminals, simply enter source ~/.zshrc in whatever terminal you'd like to keep working on.
When I try to run the command:
import psycopg2
I get the error:
ImportError: dlopen(/Users/gwulfs/anaconda/lib/python2.7/site-packages/psycopg2/_psycopg.so, 2): Library not loaded: libssl.1.0.0.dylib
Referenced from: /Users/gwulfs/anaconda/lib/python2.7/site-packages/psycopg2/_psycopg.so
Reason: image not found
So far I have tried brew install openssl and have referenced (with no luck):
psycopg2 installation error - Library not loaded: libssl.dylib
http://joshuakehn.com/2013/10/13/Postgresapp-and-psycopg2-on-OS-X.html
Psycopg2 image not found
Instead of playing with symlinks in system library dirs, set the $DYLD_FALLBACK_LIBRARY_PATH to include the anaconda libraries. eg:
export DYLD_FALLBACK_LIBRARY_PATH=$HOME/anaconda/lib/:$DYLD_FALLBACK_LIBRARY_PATH
After Homebrew wouldn't allow me to force link openssl the following worked fine:
pip install --global-option=build_ext \
--global-option="-I/usr/local/opt/openssl/include" \
--global-option="-L/usr/local/opt/openssl/lib" psycopg2
(this installation succeeded in a virtualenv on macOS)
EDIT: potentially dangerous, read comments first!
See a much safer answer below: https://stackoverflow.com/a/30726895/308315
I ran into this exact issue about an hour after you posted it and just figured it out. I am using Mac OS X Yosemite, Python 2.7, and the Postgresql app.
There seems to be a non-working symlink set by default (or I introduced it while troubleshooting), to fix it first remove the incorrect links:
$ sudo rm /usr/lib/libssl.1.0.0.dylib
$ sudo rm /usr/lib/libcrypto.1.0.0.dylib
Then re-link them with (replace YOURUSERNAME with your Mac user name. I found it helpful to use tab to complete each step, to confirm the directory):
$ sudo ln -s /Users/YOURUSERNAME/anaconda/lib/libssl.1.0.0.dylib /usr/lib
$ sudo ln -s /Users/YOURUSERNAME/anaconda/lib/libcrypto.1.0.0.dylib /usr/lib
I believe the other solutions didn't work for you because your version is in anaconda.
After bashing my head against the wall for a couple hours, these two solutions are guaranteed to work:
Option 1. This solves our problem without messing around with environment variables. Run this in your shell:
brew install --upgrade openssl
brew unlink openssl && brew link openssl --force
Boom! This upgrades the symbolic links in /usr/local for libssl and libcrypto. Now import psycopg2 works like a charm.
Option 2. If for some reason you would like to maintain the current symbolic links in usr/local, run this command in your shell:
export DYLD_FALLBACK_LIBRARY_PATH=$HOME/anaconda/lib/:$DYLD_FALLBACK_LIBRARY_PATH
Just make sure to replace $HOME/anaconda/lib above with the actual lib path. In my case, this was $HOME/miniconda2/envs/ali/lib.
This will only work for the shell/bash session you're currently in. To make the change persistent, add the export statement to your ~/.bash_profile or ~/.bashrc file.
Thoughts: IMO #1 is the proper way to deal with this problem, but I left #2 in case some people prefer working with environment variables rather than fixing symbolic links (if, for example, they have software with a dependency on the older openssl file versions).
conda install psycopg works for me. It updates the following packages
The following packages will be UPDATED:
conda: 3.19.1-py27_0 --> 4.0.5-py27_0
openssl: 1.0.2f-0 --> 1.0.2g-0
pip: 8.0.2-py27_0 --> 8.1.0-py27_0
setuptools: 19.6.2-py27_0 --> 20.2.2-py27_0
wheel: 0.26.0-py27_1 --> 0.29.0-py27_0
I was having this issue on Mac, trying ln -s was giving me
ln: /usr/lib/libssl.1.0.0.dylib: Operation not permitted
I didn't want to mess with my system. Instead What worked for me is to simply install psycopg2-binary :
pip install psycopg2-binary
This installed psycopg2-binary-2.8.3 version
In relation to X.L.'s answer above, I didn't want to use Anaconda when I'm already using pip, so I just gave it the path to the Postgres libraries which worked for me (I'm using PostgreSQL.app on Mac OS 10.10)...
export DYLD_FALLBACK_LIBRARY_PATH=/Library/PostgreSQL/9.5/lib:$DYLD_FALLBACK_LIBRARY_PATH
I had to vary Scott Brennstuhl's answer a little:
1. Remove broken symlinks:
$ sudo rm /usr/lib/libssl.1.0.0.dylib
$ sudo rm /usr/lib/libcrypto.1.0.0.dylib
$ sudo rm /usr/lib/libpq.5.dylib
Relink with postgres' included drivers:
$ sudo ln -s /Applications/Postgres.app/Contents/Versions/9.4/lib/libssl.1.0.0.dylib /usr/lib
$ sudo ln -s /Applications/Postgres.app/Contents/Versions/9.4/lib/libcrypto.1.0.0.dylib /usr/lib
$ sudo ln -s /Applications/Postgres.app/Contents/Versions/9.4/lib/libpq.5.dylib /usr/lib
My flavor of setup was a little different than the OP: I'm using Postgres.app on Mac and am within a virtualenv; but the symptoms were similar.
For me, this occurred right after updating my Postgres.app from 9.3 to 9.5 on my local, and the error clearly showed the psycopg2 path for libssl.1.0.0.dylib was pointing to the old 9.3 data directory location (the image referenced in this error?). Adding weird things to my ENV or removing symlinks I'm not sure the impact of definitely didn't feel right to me. I solved it by uninstalling then re-installing psycopg2 the same way I had when it was working - something that doesn't feel very dangerous at all:
# In my virtualenv
pip uninstall psycopg2
pip install psycopg2
Then I was all good!
Do the following to resolve Library not loaded:libssl.1.0.0.dylib error if you have openssl in /usr/local/Cellar directory
sudo cp /usr/local/Cellar/openssl/<<version>>/lib/libssl.1.0.0.dylib /usr/lib
After doing step 1, if you still get Library not loaded:libcrypto.1.0.0.dylib error. Do the following
sudo cp /usr/local/Cellar/openssl/<<version>>/lib/libcrypto.1.0.0.dylib /usr/lib
brew reinstall openssl postgres did the trick for me
I had the same problem when I updated openssl from 1.0.0 to 1.1.1d, and this fixed my problem:
brew upgrade postgresql
So first for me openssl re-install never worked. It was quite irritating that all of the above answers failed for me. To be sure that it's a openssl issue, first, install psycopg2-binary using pip
pip install psycopg2-binary
After installing psycopg2-binary, if you're getting error like ld: library not found for -lssl then do the following
export LDFLAGS="-L/usr/local/opt/openssl/lib"
export CPPFLAGS="-I/usr/local/opt/openssl/include"
if these didn't work then you can try to upgrade psycopg2 and re-check that issue still there or not.
pip install psycopg2 --upgrade
if all the above didn't worked then only try reinstalling openssl as mentioned in all above answers.
I tried pip install psycopg2 which was giving similar issues.
Then I tried conda install psycopg2, which worked!
Also make sure the pip you are using belongs to anaconda (which pip)
The solution that worked for me (https://stackoverflow.com/a/30726895 did not) was installing psycopg2-binary with: pip install psycopg2-binary==2.7.6
This is on MacOS Mohave.
I am using Mac OS Sierra:
and got this error:
Library not loaded: libssl.1.1.dylib
I found this library in
/Library/PostgreSQL/11/lib
I found this solution in internet:
export DYLD_LIBRARY_PATH=/Library/PostgreSQL/11/lib
But this is not a permanent solution. As I have to run the above command whenever I restart my server.
Add the line:
export DYLD_LIBRARY_PATH=/Library/PostgreSQL//lib
to
~/.bash_profile
Simple solution: this pip command will install a package at a specific location:
pip install psycopg2-binary -t PATH
Where PATH is a path that you specify.
To test this, install the package in a folder on your desktop.
Then put a python script in the same folder that will import psycopg2. It should work with the script being in the same location as the psycopg2 package.
Comments:
This reason we need psycopg2-binary, according to old documentation that I found online:
"The binary packages come with their own versions of a few C libraries, among which libpq and libssl , which will be used regardless of other libraries available on the client: upgrading the system libraries will not upgrade the libraries used by psycopg2 . Please build psycopg2 from source if you want to maintain binary upgradeability."
Source:
https://access.crunchydata.com/documentation/psycopg2/2.7.3/install.html#install-from-source
I realized the issue has been that python's site package directory needs to be referenced. The location for this on my computer is:
/Users/my_name/Library/Python/3.7/lib/python/site-packages
Now, if you want to use IDLE or say PyCharm as I have been, the installation of psycopg2-binary needs to target this site directory. Additionally, you'll find two folders that appear after installing psycopg2-binary called: psycopg2, psycopg2_binary-2.8.4.dist-info
I spent a long time investigating this issue. The other methods out there were not not resolving the issue as seen above regarding lib ssl and reason image not found.
Setup: macOS Catalina, Python 3.7, PyCharm/IDLE project on Desktop, openssl#1.1/1.1.1d
After trying for more than a day I came to the below solution.
brew reinstall openssl#1.0
disable csrutil -> google it how to disable it, so that we could copy something
to /usr/lib
copy libssl.1.0.0.dylib to /usr/lib
I did- sudo cp
/usr/local/Cellar/openssl/1.0.2s/lib/libssl.1.0.0.dylib /usr/lib
copy libcrypto.1.0.0.dylib to /usr/lib
I did- sudo cp
/usr/local/Cellar/openssl/1.0.2s/lib/libcrypto.1.0.0.dylib /usr/lib
Similarly, if you face issue for Library not loaded: libssl.1.0.0.dylib
just change the version from 1.0 to 1.1 of openssl and copy libssl.1.1 instead libssl.1.0 and libcrypto.1.1 instead libcrypto.1.0.0
Done you are all set to enjoy psycopg2 in mac.
Homebrew upgrades default openssl from v1.0 to v1.1. If you tried #Scott solution to upgrade openssl:
brew install --upgrade openssl
brew unlink openssl && brew link openssl --force
you may run into ssh problem. You need to upgrade openssh as well.
brew upgrade openssh
according to this blog: https://blog.junjizhi.com/all/2019/12/17/git-fetch-libssl-error.html
I encountered this problem after running brew upgrade, which updated openssl from 1.0.0 to 1.1.1. That causes the error in the question because I'm using pyscopg 2.7.4, which is pinned to openssl#1.0. More recent versions of psycopg (>2.8) are pinned to openssl#1.1.
So your options in this situation are to upgrade your psycopg version to 2.8.1 or later (in your Pipfile/Pipfile.lock, etc.), or force brew to keep using openssl#1.0 with this command, taken from https://github.com/Homebrew/homebrew-core/issues/47348#issuecomment-560001981:
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/64555220bfbf4a25598523c2e4d3a232560eaad7/Formula/openssl.rb -f
Install pip install -i https://test.pypi.org/simple/ psycopg2==2.7.6.1.dev1 worked for me
I had the problem that was originally posted in this thread. I traced it back to a problem with libpq. For me, the solution was to run
brew install postgresql,
after which psycopg2 worked like a breeze.
I am having trouble installing psycopg2. I get the following error when I try to pip install psycopg2:
Error: pg_config executable not found.
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'.
----------------------------------------
Command python setup.py egg_info failed with error code 1 in /tmp/pip-build/psycopg2
But the problem is pg_config is actually in my PATH; it runs without any problem:
$ which pg_config
/usr/pgsql-9.1/bin/pg_config
I tried adding the pg_config path to the setup.cfg file and building it using the source files I downloaded from their website (http://initd.org/psycopg/) and I get the following error message!
Error: Unable to find 'pg_config' file in '/usr/pgsql-9.1/bin/'
But it is actually THERE!!!
I am baffled by these errors. Can anyone help please?
By the way, I sudo all the commands. Also I am on RHEL 5.5.
pg_config is in postgresql-devel (libpq-dev in Debian/Ubuntu, libpq-devel on Centos/Fedora/Cygwin/Babun.)
On Mac OS X, I solved it using the homebrew package manager
brew install postgresql
Have you installed python-dev?
If you already have, try also installing libpq-dev
sudo apt-get install libpq-dev python-dev
From the article: How to install psycopg2 under virtualenv
Also on OSX. Installed Postgress.app from http://postgresapp.com/ but had the same issue.
I found pg_config in that app's contents and added the dir to $PATH.
It was at /Applications/Postgres.app/Contents/Versions/latest/bin. So this worked: export PATH="/Applications/Postgres.app/Contents/Versions/latest/bin:$PATH".
You can install pre-compiled binaries on any platform with pip or conda:
python -m pip install psycopg2-binary
or
conda install psycopg2
Please be advised that the psycopg2-binary pypi page recommends building from source in production:
The binary package is a practical choice for development and testing but in production it is advised to use the package built from sources
To use the package built from sources, use python -m pip install psycopg2. That process will require several dependencies (documentation) (emphasis mine):
A C compiler.
The Python header files. They are usually installed in a package such as python-dev. A message such as error: Python.h: No such file or directory is an indication that the Python headers are missing.
The libpq header files. They are usually installed in a package such as libpq-dev. If you get an error: libpq-fe.h: No such file or directory you are missing them.
The pg_config program: it is usually installed by the libpq-dev package but sometimes it is not in a PATH directory. Having it in the PATH greatly streamlines the installation, so try running pg_config --version: if it returns an error or an unexpected version number then locate the directory containing the pg_config shipped with the right libpq version (usually /usr/lib/postgresql/X.Y/bin/) and add it to the PATH:
$ export PATH=/usr/lib/postgresql/X.Y/bin/:$PATH
You only need pg_config to compile psycopg2, not for its regular usage.
Once everything is in place it’s just a matter of running the standard:
$ pip install psycopg2
or, from the directory containing the source code:
$ python setup.py build
$ python setup.py install
For ubuntu users, this is the solution:
sudo apt install libpq-dev
It worked for me.
On alpine, the library containing pg_config is postgresql-dev. To install, run:
apk add postgresql-dev
This is what worked for me on CentOS, first install:
sudo yum install postgresql postgresql-devel python-devel
On Ubuntu just use the equivilent apt-get packages.
sudo apt-get install postgresql postgresql-dev python-dev
And now include the path to your postgresql binary dir with you pip install, this should work for either Debain or RHEL based Linux:
sudo PATH=$PATH:/usr/pgsql-9.3/bin/ pip install psycopg2
Make sure to include the correct path. Thats all :)
You have to install libpq-dev/postgresql-libs, which is the header files and static library for compiling C programs to link with the libpq library in order to communicate with a PostgreSQL database backend.
On Arch this will run:
$ sudo pacman -S postgresql-libs
On Debian and Ubuntu:
$ sudo apt-get install libpq-dev
On Mac OS X:
$ brew install postgresql
On Red Hat/CentOS/Fedora:
$ sudo yum install postgresql-devel
apt-get build-dep python-psycopg2
Just to sum up, I also faced exactly same problem. After reading a lot of stackoverflow posts and online blogs, the final solution which worked for me is this:
1) PostgreSQL(development or any stable version) should be installed before installing psycopg2.
2) The pg_config file (this file normally resides in the bin folder of the PostgreSQL installation folder) PATH had to be explicitly setup before installing psycopg2. In my case, the installation PATH for PostgreSQL is:
/opt/local/lib/postgresql91/
so in order to explicitly set the PATH of pg_config file, I entered following command in my terminal:
PATH=$PATH:/opt/local/lib/postgresql91/bin/
This command ensures that when you try to pip install psycopg2, it would find the PATH to pg_config automatically this time.
I have also posted a full error with trace and its solution on my blog which you may want to refer. Its for Mac OS X but the pg_config PATH problem is generic and applicable to Linux also.
You should add python requirements used in Postgres on Ubuntu. Run:
sudo apt-get install libpq-dev python-dev
sudo apt-get install libpq-dev works for me on Ubuntu 15.4
I had this issue because I didn't had a postgres install. If you have brew install run
brew install postgresql
This should fix the issue.
For those running OS X, this solution worked for me:
1) Install Postgres.app:
http://www.postgresql.org/download/macosx/
2) Then open the Terminal and run this command, replacing where it says {{version}} with the Postgres version number:
export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/{{version}}/bin
e.g.
export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.4/bin
On Linux Mint sudo apt-get install libpq-dev worked for me.
UPDATE /etc/yum.repos.d/CentOS-Base.repo, [base] and [updates] sections
ADD exclude=postgresql*
curl -O http://yum.postgresql.org/9.1/redhat/rhel-6-i386/pgdg-centos91-9.1-4.noarch.rpmr
rpm -ivh pgdg-centos91-9.1-4.noarch.rpm
yum install postgresql
yum install postgresql-devel
PATH=$PATH:/usr/pgsql-9.1/bin/
pip install psycopg2
Simply run the following:
sudo apt install libpq-dev
Fixed the issue for me
Try to add it to PATH:
PATH=$PATH:/usr/pgsql-9.1/bin/ ./pip install psycopg2
Ali's solution worked for me but I was having trouble finding the bin folder location. A quick way to find the path on Mac OS X is to open psql (there's a quick link in the top menu bar). This will open a separate terminal window and on the second line the path of your Postgres installation will appear like so:
My-MacBook-Pro:~ Me$ /Applications/Postgres93.app/Contents/MacOS/bin/psql ; exit;
Your pg_config file is in that bin folder. Therefore, before installing psycopg2 set the path of the pg_config file:
PATH=$PATH:/Applications/Postgres93.app/Contents/MacOS/bin/
or for newer version:
PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.3/bin
Then install psycopg2.
I'm going to leave this here for the next unfortunate soul who can't get around this problem despite all the provided solutions. Simply use sudo pip3 install psycopg2-binary
You need to upgrade your pip before installing psycopg2. Use this command
pip install --upgrade pip
On MacOS, the simplest solution will be to symlink the correct binary, that is under the Postgres package.
sudo ln -s /Applications/Postgres.app/Contents/Versions/latest/bin/pg_config /usr/local/bin/pg_config
This is fairly harmless, and all the applications will be able to use it system wide, if required.
On Mac OS X and If you are using Postgres App (http://postgresapp.com/):
export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/latest/bin
No need to specify version of Postgres in this command. It will be always pointed to latest.
and do
pip install psycopg2
P.S: If Changes doesn't reflect you may need to restart the Terminal/Command prompt
Source
Installing python-psycopg2 solved it for me on Arch Linux:
pacman -S python-psycopg2
On Windows,
You may want to install the Windows port of Psycopg, which is recommended in psycopg's documentation.
Just solved the problem in Cent OS 7 by:
export PATH=$PATH:/usr/pgsql-9.5/bin
make sure your PostgreSql version matches the right version above.
This was partly suggested before, adding it here for clarity.
From the documentation at https://www.psycopg.org/docs/install.html.
they suggest running: $ pip install psycopg2-binary
That solved the issue for me.
Here, for OS X completeness: if you install PostgreSQL from MacPorts, pg_config will be in /opt/local/lib/postgresql94/bin/pg_config.
When you installed MacPorts, it already added /opt/local/bin to your PATH.
So, this will fix the problem:
$ sudo ln -s /opt/local/lib/postgresql94/bin/pg_config /opt/local/bin/pg_config
Now pip install psycopg2 will be able to run pg_config without issues.
To those on macOS Catalina using the zsh shell who have also installed the postgres app:
Open your ~/.zshrc file, and add the following line:
export PATH="/Applications/Postgres.app/Contents/Versions/latest/bin:$PATH"
Then close all your terminals, reopen them, and you'll have resolved your problem.
If you don't want to close your terminals, simply enter source ~/.zshrc in whatever terminal you'd like to keep working on.
A colleague got this error message when trying to use MySQLdb from Django:
[...]
ImproperlyConfigured("Error loading MySQLdb module: %s" % e) django.core.exceptions.ImproperlyConfigured:
Error loading MySQLdb module: dlopen(/Users/roy/.python-eggs/MySQL_python-1.2.3c1-py2.5-macosx-10.5-i386.egg-tmp/_mysql.so, 2):
Symbol not found: _mysql_affected_rows
Referenced from: /Users/roy/.python-eggs/MySQL_python-1.2.3c1-py2.5-macosx-10.5-i386.egg-tmp/_mysql.so Expected in: dynamic lookup
He's using OS X 10.5, Python 2.5 (arriving with OS X), MySQL 5.1 & MySQLdb 1.2.3c1.
Any idea how to attack this?
It might be best if you install mysql and it's Python bindings from scratch, I use the following steps whenever I need MySQLdb on OS X 10.4 or 10.5:
Install MySQL for your system, the dmg installer should be sufficient
The default location of MySQL will be somewhere around: /usr/local/mysql-5.0.45-osx10.4-i686. From /usr/local/mysql/lib, create a soft link:
ln -s ../../mysql-5.0.45-osx10.4-i686/lib mysql
Download the MySQLdb source and unpack it
Edit the file site.cfg under your unpacked MySQLdb directory, comment out the registry_key and set mysql_config to:
mysql_config = /usr/local/mysql-5.0.45-osx10.4-i686/bin/mysql_config
Carry on with the regular Python packages build from within MySQLdb directory:
sudo python setup.py install
If everything is fine above, test MySQLdb in a new terminal:
python -c "import MySQLdb"
The above should return nothing if successful. The above example shows OS 10.4 and MySQL 5.0, substitute them with the your proper tools version.
It was Complicated and hard but it worked on MacOSX Lion.
you will be using :
Xcode
Brew
Port
Pip
make sure that you have Xcode(4.X) installed , and your mac is configured to find the executables because it will be used by Macports during the process of installing mysql-python.
Make sure that Xcode Command line Tools are installed
start Xcode app >> preferences >> download >> Components tab >> Command Line Tools >> click install
run the following commands from the terminal.
xcodebuild -version
if you ran into this error
/usr/bin/xcodebuild -version Error: No developer directory found at /Developer
Try to Run
/usr/bin/xcode-select
this will update the developer directory path.
Then you need to switch manually to the new Xcode install dir in /Applications:
sudo /usr/bin/xcode-select -switch /Applications/Xcode.app
Ref
Uninstall mysql [Backup you data before doing so !].
sudo rm /usr/local/mysql
sudo rm -rf /usr/local/mysql*
sudo rm -rf /Library/StartupItems/MySQLCOM
sudo rm -rf /Library/PreferencePanes/My*
edit /etc/hostconfig and remove the line MYSQLCOM=-YES-
sudo rm -rf /Library/Receipts/mysql*
sudo rm -rf /Library/Receipts/MySQL*
sudo rm -rf /var/db/receipts/com.mysql.*
Use brew to install Mysql again:
brew install mysql
you might run into this error.
Error: Cannot write to /usr/local/Cellar
the fix.
you should be ready to go now.
sudo port install py27-mysql
pip install mysql-python
python -c "import MySQLdb"
if you don't see any errors MySQLdb is installed.
Yes, the MySQLDb egg was compiled against a different version of libmysqlclient than the version present in the system. You need to either get a proper egg (uninstalling the previous) or to build MySQLDb from scratch to compile it against the library present in your system.
I don't know why but I think your colleague might be interested in this question:
Configuring Django to use remote mysql server?
I had trouble with Thierry's solution on 32-bit Python (2.6.5) on OS X 10.6.
Upgrading to Python 2.7 64-bit version fixed the problem for me.
Try to run:
easy_install -U distribute
pip install --upgrade mysql-python
Note:
If you have any errors of missing symbols while compiling, you need to have mysql development libs to compile it.
On Linux it's easy to install it:
sudo apt-get install mysql-devel
or:
sudo yum install mysql-devel
On Mac you probably need to download MySQL Connector and then you may have to pass in a --with-mysql-libs option to point to the directory when the C libraries are unpacked to.
Or you can try to put the libraries in the default directory: /usr/lib64/mysql
sudo apt-get install python-mysqldb
make sure it should installed properly
or you can use another alternative like easy_install