psycopg2 library not loaded - python

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.

Related

Cannot import library covsirphy

I am trying to import library COVSIRPHY to jupyter notebook following two steps:
pip install --upgrade covsirphy (I installed it using terminal in specific environment created in anaconda navigator)
It was installed successfully
import covsirphy as cs
I typed in directly in jupyter notebook, but it occured an error:
OSError: dlopen(/opt/anaconda3/envs/test/lib/python3.9/site-packages/lightgbm/lib_lightgbm.so, 0x0006): Library not loaded: /usr/local/opt/libomp/lib/libomp.dylib
Referenced from: /opt/anaconda3/envs/test/lib/python3.9/site-packages/lightgbm/lib_lightgbm.so
Reason: tried: '/usr/local/opt/libomp/lib/libomp.dylib' (no such file), '/usr/local/lib/libomp.dylib' (no such file), '/usr/lib/libomp.dylib' (no such file)
It is trying to search a path which does not exists, but physically the file libomp.dylib is located in other path, but I have no idea why it is seeking in this path.
I am wondering whether this library is possible to install on Mac with chip M1.
enter image description here
enter image description here
Please re-install libomp to save 'libomp.dylib' file at '/usr/lib/libomp.dylib' or update PATH to include the current path.
An alternative:
Because the latest development version of covsirphy does not depend on lightgbm, try to reinstall the latest version (>= 3.0.0.dev7).
pip install --upgrade "git+https://github.com/lisphilar/covid19-sir.git#egg=covsirphy"

Error importing psycopg2 on M1 mac: incompatible architecture

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

RHEL 8 - Unable to complete pyPDF2 offline installation due to typing_extensions

I've been stuck with this problem.
I work on a UNIX RHEL8 server which did not allow to access internet.
All required packages and modules I able to install expect this pyPDF2 module due to typing_extensions
RHEL8 Python 3.6.8
Pip 9.0.3 installed but not able to use due to no internet access
PyPDF2 2.10.0 try to install using python setup.py build && python setup.py install
Installed /usr/local/lib/python3.6/site-packages/PyPDF2-2.10.0-py3.6.egg
Processing dependencies for PyPDF2==2.10.0
Searching for typing_extensions
Reading https://pypi.org/simple/typing_extensions/
Download error on https://pypi.org/simple/typing_extensions/: [Errno -2] Name or service not known -- Some packages may not be found!
Reading https://pypi.org/simple/typing-extensions/
Download error on https://pypi.org/simple/typing-extensions/: [Errno -2] Name or service not known -- Some packages may not be found!
Couldnt find index page for 'typing_extensions' (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading https://pypi.org/simple/
Download error on https://pypi.org/simple/: [Errno -2] Name or service not known -- Some packages may not be found!
No local packages or working download links found for typing_extensions
pip install method unable to be use due to no internet access
Please help me. Thank you
You need to install the package:
pip install typing-extensions
In newer Python versions that package is not required.
You can also edit the source of PyPDF2 to remove all imports of it and Literal.
You can download whl file from https://pypi.org/ for the package.
And if pip is installed it can be easily installed using :
pip install wheel_file.whl

zlib module issue for local user

My requirement is to install NodeJS using sources (v8.9.4) for a local user (no root access) on Oracle Linux. When I ran the 'configure' and 'make install' it complained that the Python version was not 2.7.
Since there was no root access and I could not upgrade Python, I installed Python for the local user with the steps below.
I downloaded the sources (Python-2.7.11) and ran the configure (with --prefix option) and 'make install'.
Updated the PATH and PYTHONPATH variables to use this version of Python for this user.
Now, when I try to configure NodeJS again, it does not complain about Python 2.7 any more but now says:
File "tools/compress_json.py", line 6, in <module>
import zlib
ImportError: No module named zlib
When I checked if zlib was on the system with 'yum list installed zlib', I see
zlib.i386 1.2.3-4.el5 installed
zlib.x86_64 1.2.3-4.el5 installed
I now do not know
how the local python version can use this zlib module (or)
how/if zlib module needs to be configured into python (or)
if Python has to be installed again with some configuration for getting the zlib module.
I've searched on google and tried a few, but there was nothing conclusive that could help.

Python module issue

I have a shared hosting environment on Bluehost. I am running a custom installation of python(+ django) with a few installed modules. All has been working, until yesterday a change was made on the server(I assume) which gave me this django error:
... File "/****/****/.local/lib/python/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/****/****/.local/lib/python/django/db/backends/mysql/base.py", line 14, in
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
ImproperlyConfigured: Error loading MySQLdb module: libmysqlclient_r.so.16: cannot open shared object file: No such file or directory
Of course, Bluehost support is not too helpful. They advised that 1) I use the default python install, because that has MySQLdb installed already. Or that 2) I somehow import the MySQLdb package installed on the default python, from my python(dont know if this can even be done). I am concerned that if I use the default install I wont have permission to install my other packages.
Does anybody have any ideas how to get back to a working state, with as little infrastructure changes as possible?
I think you upgraded your OS installation which in turn upgraded libmysqlclient and broke native extension. What you can do is reinstall libmysqlclient16 again (how to do it depends your particular OS) and that should fix your issue.
Other approach would be to uninstall MySQLdb module and reinstall it again, forcing python to compile it against a newer library.
You were right. Bluehost upgraded MySQL. Here is what I did:
1) remove the "build" directory in the "MySQL-python-1.2.3" directory
2) remove the egg
3) build the module again "python setup.py build"
4) install the module again "python setup.py install --prefix=$HOME/.local"
Morale of the story for me is to remove the old stuff when reinstalling module

Categories