pyenv icon indicating copy to clipboard operation
pyenv copied to clipboard

Strange pyenv build issue with psycopg2 and symlinks

Open BradRuderman opened this issue 10 years ago • 7 comments

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.

1__python__python2_7__and_new_issue_ _psycopg_psycopg2

In addition here is my homebrew list:

1__bradruderman_brads-macbook-pro_____zsh_

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/32693388-strange-pyenv-build-issue-with-psycopg2-and-symlinks?utm_campaign=plugin&utm_content=tracker%2F282009&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F282009&utm_medium=issues&utm_source=github).

BradRuderman avatar Apr 07 '16 02:04 BradRuderman

Did you specify some configure option (e.g. PYTHON_CONFIGURE_OPTS) when building CPython with pyenv?

yyuu avatar Apr 07 '16 04:04 yyuu

Nope! Just normal. I am using zsh with the pyenv plugin to activate.

BradRuderman avatar Apr 07 '16 04:04 BradRuderman

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).

cristiano2lopes avatar Apr 18 '16 10:04 cristiano2lopes

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.

bryan0 avatar Sep 15 '16 17:09 bryan0

ok upgrading psycopg2 to the latest version (2.6.2) works for me.

bryan0 avatar Sep 15 '16 22:09 bryan0

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 avatar Nov 27 '16 20:11 john-k-rice

@john-k-rice yeah I upgraded psycopg. I edited my comment to clarify this.

bryan0 avatar Nov 29 '16 19:11 bryan0