Strange pyenv build issue with psycopg2 and symlinks
Getting the following error. I think its related to the following resources: https://github.com/yyuu/pyenv/issues/425 http://stackoverflow.com/questions/22450848/error-loading-psycopg2-module-when-installed-from-a-wheel
I think its related to pyenv though not sure.
>>> import psycopg2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/opt/pyenv/versions/adwords/lib/python2.7/site-packages/psycopg2/__init__.py", line 50, in <module>
from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
ImportError: dlopen(/usr/local/opt/pyenv/versions/adwords/lib/python2.7/site-packages/psycopg2/_psycopg.so, 2): Symbol not found: _PyUnicodeUCS2_AsEncodedString
Referenced from: /usr/local/opt/pyenv/versions/adwords/lib/python2.7/site-packages/psycopg2/_psycopg.so
Expected in: flat namespace
in /usr/local/opt/pyenv/versions/adwords/lib/python2.7/site-packages/psycopg2/_psycopg.so
I have pyenv, pyenv-virtualenv, and postgres all installed via home-brew on mac os x 10.11.4.

In addition here is my homebrew list:

Did you specify some configure option (e.g. PYTHON_CONFIGURE_OPTS) when building CPython with pyenv?
Nope! Just normal. I am using zsh with the pyenv plugin to activate.
I have the same problem. Created python versions with system python active. Created a virtualenv from python 2.7.11 and runned pip install. I then get the same error described above.
Edit: Ok here is what worked for me: Creating the virtual env based on the system python (my system python is homebrew python). This is not great as stuff will break when i update the system version with brew upgrade. Also I'am using Postgres.app that i prepend to the path before initialising pyenv.
My theory is that the postgres libs are not being found on build time when using a version installed via pyenv (just a theory, I'am far from an expert on this issues).
Just tried using pyenv virtualenv and also get this same error with python 2.7.10. if i use my system 2.7.10 it builds without errors. I installed everything using brew.
ok upgrading psycopg2 to the latest version (2.6.2) works for me.
Been battling this as well. The only thing I found that worked is to symlink the Library/Frameworks python site-packages/psycopg2 to virtualenv site-packages/psycopg2. For example (executed from the virtualenv lib/python3.4/site-packages directory): ln -s /opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/psycopg2 psycopg2
What did you upgrade to 2.6.2? .... Never mind, I assume you upgraded psycopg2...
So, for what it's worth, for me this turned out to be a conflict between the port installed psycopg2 and a pip installed psycopg2... actually, I don't know if conflict is the right word....
I notice that the psycopg2 installation recommends installing psycopg2 with either fink or port. It only recommends pip for Windows. So, I had forgotten that, and when I set up a new virtualenv, I installed psycopg2 with pip into that environment... which doesn't work.
So, in summary, I install psycopg2 with port, then symlink the port version to the virtualenv site-packages/psycopg2
@john-k-rice yeah I upgraded psycopg. I edited my comment to clarify this.