IBM Db2 SQL Alchemy adapter -- issue with client driver [duplicate] - python

After updating to Mac Catalina (version 10.15.6), I had to re-install Python and all dependent modules.
My problem now is that when adding the module ibm_db, I get the following error message when trying to run my program:
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/ibm_db.cpython-37m-darwin.so, 2): Symbol not found: ___cxa_throw_bad_array_new_length
Referenced from: /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/clidriver/lib/libdb2.dylib
Expected in: /usr/lib/libstdc++.6.dylib
in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/clidriver/lib/libdb2.dylib
I am using PyCharm 2018.3.7 (CE).
Anyone that has seen this, and have a fix for this?

The problem is due to older version of /usr/lib/libstdc++.6.dylib installed in your system. New installation of ibm_db is looking for newer version of libstdc++.6.dylib.
There are two quick solution for it. You can use either one:
Install new gcc of version >= 8 in your system and set environment variable to use it so that libstdc++.6.dylib from new version of gcc should get picked up instead of existing old one.
OR,
export DYLD_LIBRARY_PATH=/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/clidriver/lib
Thanks.

Related

Getting the error Python.framework/Versions/2.7/Python probably after MacOS Monterey 12.3.1 update

All attempt of Git push fails probably after MacOS Monterey update 12.3.1 on MacBook with Apple silicon.
% git push
dyld[56684]: Library not loaded: /System/Library/Frameworks/Python.framework/Versions/2.7/Python
Referenced from: /usr/local/Cellar/openssh/7.9p1/bin/ssh
Reason: tried: '/System/Library/Frameworks/Python.framework/Versions/2.7/Python' (no such file), '/Library/Frameworks/Python.framework/Versions/2.7/Python' (no such file)
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.
The same problem with ssh-keygen command.
Probably it is due to the fact that Apple has removed Python from macOS.
I tried to install Python 2.7 but it didn't help.
After a day trying to download Python 2.7 and various other things, I solved this issue by renaming Python framework directory: /System/Library/Frameworks/Python.framework/Versions/3.6 from 3.6 to 2.5.
It fixed the problem.
So this might be a hot fix, but I can't recommend doing it
Try brew install openssh . It works for me

Unable to install MySQLdb on Python 2.7 on MacOS Mojave

I used to create a big program in Python 2.7 that uses MySQLdb a long time ago. I developed it both on Mac OS and PC.
I just had to re-refomat my Mac and I'm now on Mojave. Whereas I have been able in the past to easily install MySQLdb, I'm unable to do so now.
I've tried all that was available on the forums with no success.
PIP, easy-install, Brew and many other solutions that I forgot.
Even "easy_install MySQL-python" found in Installing MySQLDB on Python 2.7.3 under CentOS gave me an error ending by :
EnvironmentError: mysql_config not found
I expect to be able to "import MySQLdb" in my Python code, but MySQLdb isn't installed and so "no found"
Thanks a lot for your help.
So, you either have upgrade your MySQL Version to a 64Bit Version, get the newest MySQL-Python Connector, update your code and use this instead of MySQLdb. Which is the safest and best solution, but u have to put in some work (no problem if your code isn't that long anyways...)
https://dev.mysql.com/downloads/connector/python/
https://dev.mysql.com/doc/connector-python/en/connector-python-example-connecting.html
import mysql.connector
Second chance is, staying with your old 32Bit MySQL Version (for Example 5.6.20 32Bit), and still using the same old MySQL Python Connector (For Example Mysql-Python Connector 1.2.3 in 32Bit, found on the Mysql Download page aswell) you used before. There will be some popup errors, such as a few Libraries are out of date and probably not compatible anymore, but it's working.

Mac OSX-Lion Python-LDAP Unrecognized Symbol: _ber_pvt_opt_on

I've been trying to run a web server based in Python 2.6 code here at work. The server requires the python LDAP libraries in order to run. Because I'm working on Mac OS X Lion, I needed to run a manual install of python-ldap 2.4.7 in order to get Python to recognize LDAP at all. Python-ldap appeared to intall correctly, but when I try to run the web server I get the following error (I added some line breaks for the sake of clarity):
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/python_ldap-2.4.7-py2.6-macosx-10.7-fat.egg/_ldap.so, 2): Symbol not found: _ber_pvt_opt_on
Referenced from: /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/python_ldap-2.4.7-py2.6-macosx-10.7-fat.egg/_ldap.so
Expected in: flat namespace
in /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/python_ldap-2.4.7-py2.6-macosx-10.7-fat.egg/_ldap.so
I'm using OpenLDAP 2.4.21, and I set the following system variables before running my python-ldap installation:
export ARCHFLAGS="-arch i386"
export CFLAGS="-isysroot /Developer/SDKs/MacOSX10.7.sdk -arch i386"
export MACOSX_DEPLOYMENT_TARGET="10.7"
I should also probably mention that I've had to force everything I've installed to use 32-bit architecture instead of 64-bit in order to work around some issues with Oracle's 64-bit support. Has anyone encountered a similar situation, or do they know the significance of the "_ber_pvt_opt_on" symbol that LDAP was looking for? The number of Google results I was able to come up with was both small and unhelpful. Any light that you could shed on the situation would be greatly appreciated.

No module named psycopg2

I have Django project which uses postgresql 9. I installed psycopg2 and when I run project I receive 'Error loading psycopg2 module: dll load failed'. I met this issue for the first time. I have windows 7 x64 with python2.7. How can I solve this one?
I had the same problem, it was that psycopg2 does not install well in Windows with _easy_install_, I followed the instructions on the follow SO answer:
Installing psycopg2 (postgresql) in virtualenv on windows
You need to manually install the psycopg2 exe file:
psycopg2-2.4.2.win-amd64-py2.7-pg9.0.4-release.exe
I know this is going to haunt me again or as nwcell puts it:
Every time I need to set up psycopg2 on windows, I wind up wanting to shoot something.
I actually have a machine with it working and I've been at pains to setup another machine. I installed Python 3.8 and the old PC has 3.7.4. The main difference was the file:
C:\project\venv\Lib\site-packages\psycopg2_psycopg.cp37-win32.pyd
On the new PC it was showing as AMD64. I eventually uninstalled 3.8 and reverted back to 3.7.4, then I copied the files from the old PC to the new and then I hit this error:
https://stackoverflow.com/a/37819509/495455
Going to a WayBackMachine version of the stickpeople:
https://web.archive.org/web/20191003103502/http://www.stickpeople.com/projects/python/win-psycopg/
I didn't install the exe, I simply did a pip install -Iv psycopg2-binary==2.8.4 at which point it started working. So I'm thinking the latest version doesn't work, for me 2.8.4 still works: https://pypi.org/project/psycopg2/#files
It's something to do with x64 as everything I tried with AMD64 didn't work and I spent ages on it.

How do I get ibm_db or PyDB2 python modules to work with DB2 in Mac OS X 10.7 Lion?

I used this question/answer to install DB2 in Lion: How do I install IBM DB2 Express-C on Mac OS X 10.7 Lion?
After configuring my databases, I am able to use db2 from the command line to execute queries, but the python modules ibm_db and PyDB2 both fail to import with the following error:
>>> import ibm_db
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dlopen(/Library/Python/2.7/site-packages/ibm_db-1.0.4-py2.7-macosx-10.7-intel.egg/ibm_db.so, 2): Symbol not found: _dsIsDirServiceRunning
Referenced from: /Users/<username>/sqllib/lib64/libdb2.dylib
Expected in: /System/Library/Frameworks/DirectoryService.framework/Versions/A/DirectoryService
How can I fix this and get ibm_db and PyDB2 to work properly with DB2 in Lion?
edit: moved answer to answers
Answer:
The problem is that a particular symbol in the DirectoryService framework was finally removed in Lion (it was deprecated in 10.2). libdb2.dylib, which is installed by DB2 Express-C attempts to call this function, and causes the error when importing either python module.
To work around this, you need to configure your environment to link against an older version of the DirectoryService framework. To do this, you will need an installation of Snow Leopard (it may work with older versions, but I have not tested it, and you will want the newest you can get your hands on, that isn't Lion, of course). You will find the DirectoryService framework installed here:
/System/Library/Frameworks/DirectoryService.framework/
Copy that directory from a Snow Leopard installation to any location you want in your Lion installation. For this example, I copied the DirectoryService.framework directory into a directory named OldFrameworks in ~ :
~/OldFrameworks/DirectoryService.framework/
Set the environment variable $DYLD_LIBRARY_PATH to contain the path to the actual library:
export DYLD_LIBRARY_PATH=${HOME}/OldFrameworks/DirectoryService.framework/Versions/Current/:${DYLD_LIBRARY_PATH}
Any environment in which you perform the above command will be configured to allow python to import ibm_db or PyDB2. Add it to your .profile, .bashrc, etc. to permanently configure your environment. Remember, though, this means all commands executed in the configured environment will attempt to link against the snow leopard version of DirectoryService. This could potentially cause errors with other tools (I have yet to encounter any). It would be prudent to only set DYLD_LIBRARY_PATH in shells where you need it.
You can change the db2 libraries using install_name_tool to look at the copied version of DirectoryService.framework, so you don't have to change DYLD_LIBRARY_PATH
Full credit goes to the following, I am simply updating this thread having been through the process of install db2 / ibm_db on Lion and finding this thread as one of the top hits via Google.
http://www.ibm.com/developerworks/forums/thread.jspa?threadID=238136&start=30&tstart=0
with other options described here:
http://www.ibm.com/developerworks/forums/message.jspa?messageID=14604855#14604855
The answer (should the above thread disappear):
Copy the Snow Leopard DirectoryService.framework to
/opt/SL_Frameworks/DirectoryService.framework
Then
cd /opt/IBM/db2/V9.5/
install_name_tool -change /System/Library/Frameworks/DirectoryService.framework/Versions/A/DirectoryService /opt/SL_Frameworks/DirectoryService.framework/Versions/A/DirectoryService lib64/libdb2sec.dylib
install_name_tool -change /System/Library/Frameworks/DirectoryService.framework/Versions/A/DirectoryService /opt/SL_Frameworks/DirectoryService.framework/Versions/A/DirectoryService lib64/libdb2.dylib
The referenced post mentions changing a third library
libdb2e.dylib
however, I have only installed the db2 client to use the ibm_db python module and this library is not present.
The easiest solution to install ibm_db on MacOS is to run the below command:
pip3 install --no-binary "ibm_db" ibm_db
Regards,

Categories