Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[macOS 11.01, M1 Chip] Symbol not found: _PQbackendPID #1208

Closed
djch opened this issue Dec 7, 2020 · 10 comments
Closed

[macOS 11.01, M1 Chip] Symbol not found: _PQbackendPID #1208

djch opened this issue Dec 7, 2020 · 10 comments

Comments

@djch
Copy link

djch commented Dec 7, 2020

Hello there. I'm trying to get psycopg2-binary running on Python 3.9.0 running natively on Apple Silicon architecture. The installation is successful, but if I try to run Django (2.2.17 in this case) I receive the following error:

❯ pipenv run ./manage.py check 

Traceback (most recent call last):
  File "/Users/dan/.local/share/virtualenvs/in-tellinc.com.au-umO7OOcD/lib/python3.9/site-packages/django/db/backends/postgresql/base.py", line 20, in <module>
    import psycopg2 as Database
  File "/opt/homebrew/lib/python3.9/site-packages/psycopg2/__init__.py", line 51, in <module>
    from psycopg2._psycopg import (                     # noqa
ImportError: dlopen(/opt/homebrew/lib/python3.9/site-packages/psycopg2/_psycopg.cpython-39-darwin.so, 2): Symbol not found: _PQbackendPID
  Referenced from: /opt/homebrew/lib/python3.9/site-packages/psycopg2/_psycopg.cpython-39-darwin.so
  Expected in: flat namespace
 in /opt/homebrew/lib/python3.9/site-packages/psycopg2/_psycopg.cpython-39-darwin.so

Install log:

❯ pip3.9 install psycopg2-binary  
Collecting psycopg2-binary
  Using cached psycopg2_binary-2.8.6-cp39-cp39-macosx_11_0_arm64.whl
Installing collected packages: psycopg2-binary
Successfully installed psycopg2-binary-2.8.6

I realise that Apple Silicon is very new and not officially supported by most projects, but if anyone has time to help, I'd super appreciate it. Thanks.

@djch djch changed the title [macOS Big Sur, M1 Chip ] Symbol not found: _PQbackendPID [macOS 11.01, M1 Chip ] Symbol not found: _PQbackendPID Dec 7, 2020
@dvarrazzo
Copy link
Member

#1200

@djch djch changed the title [macOS 11.01, M1 Chip ] Symbol not found: _PQbackendPID [macOS 11.01, M1 Chip] Symbol not found: _PQbackendPID Dec 8, 2020
@ValerioMC
Copy link

Same problem and save environment here... i spent 1 day around this problem.
Are you creating venv using pycharm? this was the problem in my case. I deleted venv created by pycharm and i created it manually with python3 -m venv /path/to/venv then activate and pip3 install -r requirements.txt runs perfectly

@djch
Copy link
Author

djch commented Jan 27, 2021

@ValerioMC FYI, I gave up on it eventually. Installed postgresql@12 via homebrew and linked those libraries via ~/.zshrc

@breno-dsuite
Copy link

My two cents... solved by brew install libpq
and then adding libpq to ~/.zshrc

@jda3000
Copy link

jda3000 commented Feb 17, 2021

Same problem and save environment here... i spent 1 day around this problem.
Are you creating venv using pycharm? this was the problem in my case. I deleted venv created by pycharm and i created it manually with python3 -m venv /path/to/venv then activate and pip3 install -r requirements.txt runs perfectly

Brilliant Thank You

@feconroses
Copy link

Hey 👋 I struggled with installing psycopg2 on the new Apple Mac M1. The solution that finally worked for me for installing not only psycopg2, but also other packages (e.g. pandas and numpy) was using Conda. Created a virtual environment with conda, installed these packages that were having some problems with the M1 (such as psycopg2) with conda install psycopg2 and it worked!

@asuraphel
Copy link

asuraphel commented Apr 15, 2021

Hi everyone. After trying everything out, the solution that worked was this one. Important! Don't forget to add --no-cache-dir to the pip install psycopg2, however.

@john-mcgowan1992
Copy link

For what it's worth, I followed all of the above and linked advice to no avail. I was only able to get everything working from the advice here after deleting and recreating the virtualenv that I'd been using with my project. Deleting and reinstalling with --no-cache-dir... so for those still stuck try deleting you virtualenv if you're using one and then following the steps from there

@psycopg psycopg deleted a comment from AnishKaliraj Sep 1, 2021
@dvarrazzo
Copy link
Member

Deleted last nonsense comment.

@AhmadAbuRjeila
Copy link

What worked with me on M1 Chip

  1. Remove virtual env (if already created)
  2. Open Rosetta terminal (if you don't know how, check this please https://www.courier.com/blog/tips-and-tricks-to-setup-your-apple-m1-for-development)
  3. Go to your project folder
  4. Create virtual env python3 -m venv venv
  5. Use created virtual env source venv/bin/activate
  6. Install binary package of psycopg2 pip install psycopg2-binary==2.9.2

@psycopg psycopg locked as resolved and limited conversation to collaborators Dec 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants