When I try importing psycopg2, I get this error message:
ImportError: dlopen(/opt/homebrew/lib/python3.10/site-packages/psycopg2/_psycopg.cpython-310-darwin.so, 0x0002): Library not loaded: /opt/homebrew/opt/postgresql/lib/libpq.5.dylib
Referenced from: /opt/homebrew/lib/python3.10/site-packages/psycopg2/_psycopg.cpython-310-darwin.so
Reason: tried: '/opt/homebrew/opt/postgresql/lib/libpq.5.dylib' (no such file), '/usr/local/lib/libpq.5.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e')), '/usr/lib/libpq.5.dylib' (no such file), '/opt/homebrew/Cellar/postgresql#14/14.5_3/lib/libpq.5.dylib' (no such file), '/usr/local/lib/libpq.5.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e')), '/usr/lib/libpq.5.dylib' (no such file)
Does anyone know how to resolve this error?
I had the same problem over some Postgres upgrade. Reinstalling psycopg2-binary solved the problem as it was a caching issue for me.
pip install psycopg2-binary --force-reinstall --no-cache-dir
For Mac M1 users;
pip install -i https://test.pypi.org/simple/ psycopg2-binary==2.9.3
This will solve the problem.
Thanks
https://github.com/PostgresApp/PostgresApp/issues/83#issuecomment-1232400894
ln -s /opt/homebrew/opt/postgresql/lib/postgresql#14/* /opt/homebrew/opt/postgresql/lib/
worked for me
Related
I installed psycopg2 using pip but when I import psycopg2 I get this error
ImportError: dlopen(/Users/lce21/Documents/GitHub/hazen-web-
app/hazen-web-app/lib/python3.8/site-
packages/psycopg2/_psycopg.cpython-38-darwin.so, 0x0002): Library
not loaded: /usr/local/opt/postgresql/lib/libpq.5.dylib
Referenced from: /Users/lce21/Documents/GitHub/hazen-web-
app/hazen-web-app/lib/python3.8/site-
packages/psycopg2/_psycopg.cpython-38-darwin.so
Reason: tried: '/usr/local/opt/postgresql/lib/libpq.5.dylib'
(no such file), '/usr/local/lib/libpq.5.dylib' (no such file),
'/usr/lib/libpq.5.dylib' (no such file),
'/usr/local/Cellar/postgresql#14/14.6/lib/libpq.5.dylib' (no such
file), '/usr/local/lib/libpq.5.dylib' (no such file),
'/usr/lib/libpq.5.dylib' (no such file)
Things tried:
pip install psycopg2-binary
MacOS pip install psycopg2 with sudo and in the venv. No errors when I installed. Postgres installed.
I might need to change location of files but I don't know how to do that
I found the problem was that I had installed in my system a different version of postgresql than the version on my virtual env.
So I had to unistall from the system postgresql and then reinstall it.
For a given Django Project (to which I'm new) I need to install GDAL version: x86_64 because whenever I try python manage.py migrate on my Django project I get the following error:
OSError: dlopen(/Users/name/lib/libgdal.dylib, 0x0006): tried:
'/Users/name/lib/libgdal.dylib' (mach-o file, but is an incompatible
architecture (have 'arm64', need 'x86_64'))....
I tried to switch the architecture of the terminal from arm64 to i386 and download it with the that architecture but I get the same error.
In my settings.py the libraries GDAL and GEOS variable are declared as follows:
GDAL_LIBRARY_PATH = '/opt/homebrew/opt/gdal/lib/libgdal.dylib'
GEOS_LIBRARY_PATH = '/opt/homebrew/opt/geos/lib/libgeos_c.dylib'
I searched and tried a lot of things, but nothing worked - have anyone had the same problem?
I successfully solved it with the answer from Ronald (M1 Mac - GDAL Wrong Architecture Error [Django])
I had to download both with a arm64 architecture, because my python was arch x86_64.
I am recieving this error when installing and running
from ortools.constraint_solver import pywrapcp
after following this guide. https://developers.google.com/optimization/install/python/mac
I am using a 2019 MacBook Pro (V 12.4, Python 3.9.4), which is x86, and not M1. However, the error is regarding the module not being compatible with M1 Macs, which should not apply. All information available online is about the error regarding M1 Macs. Any help is appreciated!
ImportError: dlopen([path], 0x0002): tried: '[path]/my_env/lib/python3.9/site-packages/ortools/linear_solver/_pywraplp.so' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64h'))
M1 only wheel package have been named universal2 by pypa tools so any intel based mac currently pull it -> runtime issue.
On my way to fix our upload and release script, sorry for the inconvenience...
note: issue tracked in https://github.com/google/or-tools/issues/3436
note2: one workaround would be to download "locally" the correct wheel package then install it cd <you_download_dir>; python -m pip install --find-links=. ortools
try forcing the arch to x64_64.
For some reason, brew python tags aarch64 wheel as universal, and x86_64 as x86_64.
When I pip install SQLAlchemy, there was an error:
ImportError: dlopen(/Users/michaelgao/miniforge3/lib/python3.9/site-packages/psycopg2/_psycopg.cpython-39-darwin.so, 0x0002): tried: '/Users/michaelgao/miniforge3/lib/python3.9/site-packages/psycopg2/_psycopg.cpython-39-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e')), '/usr/local/lib/_psycopg.cpython-39-darwin.so' (no such file), '/usr/lib/_psycopg.cpython-39-darwin.so' (no such file)
Other stackexchange articles (ImportError when importing psycopg2 on M1), suggest installing psycopg2-binary, but that doesn't seem to work with sqlalchemy, b/c sqlalchemy calls psycopg2. any ideas?
Followed this guide (Cannot pip install mediapipe on Macos M1) to install Mediapipe on M1 mac, and now I am unable to use pandas or numpy.
ImportError: dlopen(/Users/matthewcuevas/Library/Python/3.8/lib/python/site-packages/pandas/_libs/interval.cpython-38-darwin.so, 0x0002): tried: '/Users/matthewcuevas/Library/Python/3.8/lib/python/site-packages/pandas/_libs/interval.cpython-38-darwin.so' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64'))
I got an error like this too. Solved it after a lot of trial & error.
The Problem: my brew was still running on Rosetta. Fixed that by uninstalling, cleaning and reinstalling. So everything seemed to run fine. Except this problem still kept cropping up
Until I discovered that pip is quite agressive in caching. So it caches the build even if the architecture changed. Solution: pip cache purge. Or remove the whole cache directory which you find with pip cache info
This will not be answer to your question/specific situation (most probably), but I got this issue when using python built for pyenv/virtualenv, and rm -rf ~/.pyenv helped me. So, python was reinstalled (properly this time; reinstalled by other scripts in our CI, because I deleted installation), and it's built for x86 and works fine on arm.
I solved by installing with conda instead of pip.
So, instead of
pip install pydantic==yourversion
Use:
conda install pydantic==yourversion.
Or, you can try installing with --no-binary (it saved me in a similar issue):
pip install pydantic==version --no-binary :all:
Go to Applications -> Xcode, then right click and select get info.
Then enable checbox "Open using Rosetta"
Finally close Xcode and open it and try again.