psycopg2 error: Library not loaded: #rpath/libssl1.1.dylib when running tox pytest - postgresql

I am unable to run my unit tests in Python3.7/pytest. The app is a flask-restplus application, and I am using sqlalchemy and psycopg2 to interact with a PostgreSQL10 database. This code used to work before updating my system. After running brew update and brew upgrade awhile back, openssl was installed as openssl#1.1 and specifically openssl#1.1.1b. The exact error I receive is
E ImportError: dlopen(/Users/myuser/myproject/.tox/dev/lib/python3.7/site-packages/psycopg2/_psycopg.cpython-37m-darwin.so, 2): Library not loaded: #rpath/libssl.1.1.dylib
E Referenced from: /Users/myuser/myproject/.tox/dev/lib/python3.7/site-packages/psycopg2/_psycopg.cpython-37m-darwin.so
E Reason: image not found
Also, I am running OSX Mojave version 10.14.4.
I have tried symlinking the library and reinstalling openssl as well as the other methods as mentioned here: psycopg2 installation error - Library not loaded: libssl.dylib. Note that I changed the openssl version in the symlink to 1.1 instead of 1.0 but that still did not fix the situation.
I expect the tests to pass (they do on coworkers setup, which is the same MacBook, OS Version and homebrew setup), but any test that has any interaction with the database fails with the above error.

Related

Import psycopg2 to establish a connection to postgres server, and interact with it in python

I am on the Udacity Full Stack Nanodegree and the instructions are not very clear for installing psycopg2 on visual studio code for postgresql. I am using postgresql15
PLEASE HELP, i've spent 4 days trouble shooting instead of attempting my 1st project
I have installed the psycopg2 using the following commands and its says it has been satisfied, however it's still not allowing me to use psycopg2:
brew install openssl
Downloading https://formulae.brew.sh/api/cask.json
100.0%
Warning: openssl#3 3.0.8 is already installed and up-to-date.
To reinstall 3.0.8, run:
brew reinstall openssl#3
ada#adas-mbp ~ % export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/
ada#adas-mbp ~ % pip3 install psycopg2
Requirement already satisfied: psycopg2 in ./.pyenv/versions/3.9.5/lib/python3.9/site-packages (2.9.5)
My visual studio code is not connecting to the database:
Exception has occurred: ImportError
dlopen(/Users/ada/.pyenv/versions/3.9.7/lib/python3.9/site-packages/psycopg2/_psycopg.cpython-39-darwin.so, 2): Library not loaded: #rpath/libssl.1.1.dylib
Referenced from: /Users/ada/.pyenv/versions/3.9.7/lib/python3.9/site-packages/psycopg2/_psycopg.cpython-39-darwin.so
Reason: image not found
File "/Users/ada/class-demos/demo.py", line 1, in <module>
import psycopg2
ImportError: dlopen(/Users/ada/.pyenv/versions/3.9.7/lib/python3.9/site-packages/psycopg2/_psycopg.cpython-39-darwin.so, 2): Library not loaded: #rpath/libssl.1.1.dylib
Referenced from: /Users/ada/.pyenv/versions/3.9.7/lib/python3.9/site-packages/psycopg2/_psycopg.cpython-39-darwin.so
Reason: image not found

cannot link libpq on Mac M1

I've been trying to run the Rust Diesel crate on my Macbook M1 and it doesn't work. The final part of the compilation gets broken by the following error:
= note: ld: warning: ignoring file /usr/local/Cellar/libpq/14.1/lib/libpq.dylib, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
Undefined symbols for architecture arm64:
When I get the info for libpq I get the following:
maxwellflitton#Maxwells-MacBook-Pro vanguard % brew info libpq
libpq: stable 14.1 (bottled) [keg-only]
Postgres C API library
https://www.postgresql.org/docs/14/libpq.html
/usr/local/Cellar/libpq/14.1 (2,335 files, 27.8MB)
Poured from bottle on 2022-01-09 at 00:14:32
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/libpq.rb
License: PostgreSQL
==> Dependencies
Required: krb5 ✔, openssl#1.1 ✔
==> Caveats
libpq is keg-only, which means it was not symlinked into /usr/local,
because conflicts with postgres formula.
If you need to have libpq first in your PATH, run:
echo 'export PATH="/usr/local/opt/libpq/bin:$PATH"' >> ~/.zshrc
For compilers to find libpq you may need to set:
export LDFLAGS="-L/usr/local/opt/libpq/lib"
export CPPFLAGS="-I/usr/local/opt/libpq/include"
I've tried installing with the following command:
RUSTFLAGS='-L /usr/local/Cellar/libpq/14.1/lib' cargo install diesel_cli --no-default-features --features postgres --force
But I still get the same error. Will it just be easier to wipe the whole thing and start again and if so how would I do this? Other people on the internet using the M1 seem to be able to get round the problem with a simple brew install libpq. Never had any issues with my previous intel mac. My ~/.cargo/config.toml has the following configuration:
[target.aarch64-apple-darwin]
rustflags = '-L /usr/local/Cellar/libpq/14.1/lib -L /opt/homebrew/lib'
Surprisingly this worked
brew install postgresql libpq
cargo clean
cargo build
cargo install diesel_cli --no-default-features --features postgres
I think it had to do with installing diesel-cli before installing the necessary dependencies. Cleaning the cargo dependencies and reinstalling worked for me
on my M1 mac, I installed the postgresql client and library with brew:
brew install postgresql libpq
and attempted to install diesel_cli again, this time it worked fine:
cargo install diesel_cli --no-default-features --features postgres
for some reason, simply installing libpq was not enough to install diesel_cli, i had to install the postgres library and the client.
Encountered a similar problem, and the issue was coming from my brew config (I restored my filesystem from my mac Intel) :
❯ brew config
...
macOS: 12.6-x86_64
...
Therefore, brew was downloading packages built for intel processors. I uninstalled and reinstalled brew following their website and now brew config is correct:
❯ brew config
...
macOS: 12.6-arm64
...
Hope this helps!
I have a Mac M1 and installed both postgresql and libpq with brew
I eventually succeeded in installing diesel_cli with these lines in my ~/.cargo/config.toml file
[target.aarch64-apple-darwin]
rustflags = '-L /opt/homebrew/opt/libpq/lib -L /opt/homebrew/lib'
source was https://github.com/diesel-rs/diesel/issues/2605

Mongodump/OpenSSL - "image not found" error

I recently updated macOS to Catalina and mongodump is no longer working. I've updated
dyld: Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib
Referenced from: /usr/local/opt/mongodb#3.6/bin/mongodump
Reason: image not found
I see a few questions out there such as this one: dyld: Library not loaded: /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib. This is the accepted response:
brew update && brew upgrade
brew uninstall openssl
brew install https://github.com/tebelorg/Tump/releases/download/v1.0.0/openssl.rb
However, I get this error when trying to install version 1.0.0:
Error: Calling Non-checksummed download of openssl formula file from an arbitrary URL is disabled! Use 'brew extract' or 'brew create' and 'brew tap-new' to create a formula file in a tap on GitHub instead.
Is there any way around this? I'm not really sure where to go from that message.
You can check which version of Homebrew is installed by running brew --version
You can use my previous response to implement how Homebrew now suggests it. Or if you want to use previous version of Homebrew to use these commands then follow this:
Go to Homebrew folder cd /usr/local/Homebrew/
Checkout to the previous version by running git checkout 2.3.0
To install OpenSSL HOMEBREW_NO_AUTO_UPDATE=1 brew install https://github.com/tebelorg/Tump/releases/download/v1.0.0/openssl.rb
Source: https://github.com/kelaberetiv/TagUI/issues/635#issuecomment-699482920

Error: No module named 'PyQt5.sip' - When installing eric6-19.03

I have noticed a number of similar questions on stackoverflow, but none that really helped me with my current challenge. I have been attempting to install eric6 on my Raspberry Pi setup. And then I encountered the following messages:
Checking dependencies
Python Version: 3.6.8
PyQt5 could not be detected.
Error: No module named 'PyQt5.sip'
Shall 'PyQt5' be installed using pip? (Y/n) Y
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: PyQt5 in /usr/local/lib/python3.6/site-packages (5.12)
Sorry, please install PyQt5.
Error: No module named 'PyQt5.sip'
And when I attempt to use the pip list to look at what has been installed (as I previously already managed to make and install the PyQt5 from source code):
Package Version
---------- -------
pip 19.0.3
PyQt5 5.12
setuptools 40.6.2
sip 4.19.14
So, how do I overcome the issue that I am currently facing? By the way, I am using the following command when attempting to install eric6:
python3 install.py
Thought you might need to know that if it helps.
Python 3.6 isn't available in any Raspbian distribution, so I assume you installed this yourself. You can't install an out-of-distribution Python version and expect distribution Python packages to work. You have PyQt5 installed, yes, but it's the version of PyQt built for Python 3.5 (I'm assuming you're on Raspbian Stretch).
Sometimes you can install Python libraries with pip, and in theory that could work to install the correct version of PyQt for your version of Python, but PyQt only provides wheels for x86 on PyPI, not for Arm, so PyQt is not pip installable on the Pi. The only way to get PyQt on Raspberry Pi is via apt, where your choices are Jessie (old stable - with Python 3.4), Stretch (current stable - with Python 3.5), and Buster (unstable/testing - with Python 3.7). If there's a need for Python >3.5, your best bet is to try upgrading to Buster, but bear in mind it's not ready for release yet.

vapor toolbox broken after upgrading swift

Vapor toolbox is crashing when trying to use it after upgrading to Swift 3.1.
dyld: lazy symbol binding failed: Symbol not found: __TTSfq4n_s___TFVSS13CharacterView38_measureExtendedGraphemeClusterForwardfT4fromVVSS17UnicodeScalarView5Index_Si
Referenced from: /usr/local/bin/vapor
Expected in: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/libswiftCore.dylib
dyld: Symbol not found: __TTSfq4n_s___TFVSS13CharacterView38_measureExtendedGraphemeClusterForwardfT4fromVVSS17UnicodeScalarView5Index_Si
Referenced from: /usr/local/bin/vapor
Expected in: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/libswiftCore.dylib
Swift ABI is not yet stable. Thus, Swift programs (like Vapor Toolbox) must be recompiled to work with new versions of the language.
Reinstall with Brew
Simply re-installing the toolbox should fix this issue.
brew reinstall vapor/tap/vapor
Replace Old Installation With Brew
You may need to delete the existing executable if you did not originally install with Homebrew
rm /usr/local/bin/vapor
Then ensure the executable is gone
which vapor
You can now install with brew
brew install vapor/tap/vapor
You can simply delete Vapor executable from
/usr/local/bin
And then run the toolbox install script from the documentation
curl -sL toolbox.vapor.sh | bash