ibmdb / python-ibmdb

Automatically exported from code.google.com/p/ibm-db
Apache License 2.0
305 stars 191 forks source link

IBM DB not working on M1 Macs even after with x86 version of python #797

Closed nanthakumaran-s closed 1 year ago

nanthakumaran-s commented 1 year ago

After using python x86 on my m1 mac, ibm_db is not working and leaving this error when using it with flask.

Traceback (most recent call last):
  File "app.py", line 3, in <module>
    import ibm_db
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/ibm_db.cpython-39-darwin.so, 0x0002): 
Symbol not found: (___cxa_throw_bad_array_new_length)
  Referenced from: '/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/clidriver/lib/libdb2.dylib'
  Expected in: '/usr/lib/libstdc++.6.dylib'

Python: 3.9.10 Architecture: x86 IBM Cloud CLI: 2.10.0+e37e09e-2022-08-24T17:38:21+00:00 ibm_db: 3.1.3

bimalkjha commented 1 year ago

@nanthakumaran-s From error it looks, ibm_db fails while loading /usr/lib/libstdc++.6.dylib which is pointing to an unavailable file. gcc is not coming with latest MacOS by default now from v12.1 onwards. So, you need to install gcc using below commands for ibm_db to work. ibm_db has dependency on gcc libs.

brew tap homebrew/homebrew-core
brew update
brew search gcc@8
brew install gcc@8

After installation of gcc it should work. If not, then share the output of ls /usr/local/lib/gcc command and add /usr/local/lib/gcc/8 into PATH and DYLD_LIBRARY_PATH system environment variables. If still it throws error, then copy /usr/local/lib/gcc/8/libstdc++.6.dylib as /usr/lib/libstdc++.6.0.9.dylib and try. Thanks.

nanthakumaran-s commented 1 year ago

@bimalkjha Thanks for helping out. I have installed homebrew for arm64 architecture. Installing gcc@8 throws

gcc@8: The x86_64 architecture is required for this software.
Error: gcc@8: An unsatisfied requirement failed this build.

Will later versions of GCC solve the problem or need to use an x86_64 architecture of homebrew ??

bimalkjha commented 1 year ago

@nanthakumaran-s It seems you have installed x86 version of python which is 32bit. I think your system is 64bit, so you should install x86_64 version of python and gcc both. For python 3.9.10, download and install this python: https://www.python.org/ftp/python/3.9.10/python-3.9.10-macosx10.9.pkg i.e. intel-only installer. Thanks.

nanthakumaran-s commented 1 year ago

@bimalkjha I have the x86 version of python which is actually 64bit. Kindly take a look at this

image
bimalkjha commented 1 year ago

@nanthakumaran-s The 64bit python should be x86_64 version not x86 version. In your first post, you mentioned x86 and not x86_64. If gcc8 installation is throwing error, try to install gcc@10. I have installed gcc@10 on my M1 Chip mac system without any issue. You can also google to find more info about how to install gcc on macos M1 Chip system. Thanks.

rajpatel794 commented 1 year ago

@bimalkjha facing the same issue(using M1 mac) and tried installing gcc. Only able to install gcc@12, but not able to install other versions. It will be helpful if you can give some information on how to install other versions. Tried with rosetta2 to install x86_64 version gcc, but not able to install it as it's throwing error- "Your Command Line Tools (CLT) does not support macOS 13."

Is any other option on how can I use ibm_db on M1 mac?

rajpatel794 commented 1 year ago

@nanthakumaran-s If you found any solution for your system on how to use it, please help me with the same.

jonathanloske commented 1 year ago

@nanthakumaran-s, @rajpatel794 x86_64 version of homebrew was the best solution for me. It sucks because this creates a lot of other problems but at least this works. I recommend also uninstalling arm64 version of homebrew before you install the x86_64 one, this makes the solution very reliable.

bimalkjha commented 1 year ago

@rajpatel794 I think gcc@12 should also work. If you have tried using ibm_db with gcc@12 and getting same error, then need to add /usr/local/lib/gcc/12 in DYLD_LIBRARY_PATH environment variable and try.

The root cause of this issue on M1 Chip system is a the file pointed out by /usr/lib/libstdc++.6.dylib is deleted. So, if you copy /usr/local/lib/gcc/12/libstdc++.6.0.9.dylib as /usr/lib/libstdc++.6.0.9.dylib, the issue should get resolved.

If it still fails, then please uninstall and reinstall ibm_db and share complete output of below commands:

cd ...../site-packages/
rm -rf clidriver ibm_db*
pip install ibm_db
otool -L ibm_db.cpython-39-darwin.so
otool -L clidriver/lib/libdb2.dylib
echo $DYLD_LIBRARY_PATH
echo $PATH
ls -l /usr/lib/libstdc++.6.dylib
ls /usr/local/lib/gcc
db2level

Thanks.

a473000 commented 1 year ago

Hi can anyone help I have mac mini , M1 and I have the same problem Traceback (most recent call last): File "app.py", line 3, in import ibm_db lopen(/Users/przemyslawczekaj/opt/anaconda3/lib/python3.9/site-packages/ibm_db.cpython-39-darwin.so, 0x0002): Symbol not found: ___cxa_throw_bad_array_new_length Referenced from: /Users/przemyslawczekaj/opt/anaconda3/lib/python3.9/site-packages/clidriver/lib/libdb2.dylib Expected in: <2A79FF3C-D69D-37A4-88B0-56DC4EB30F49> /usr/lib/libstdc++.6.dylib

Can any one provide steps one by one how to fix this, thanks I have this brew and gcc but I do not know what to change in order for it to work thanks

Aslo on mac book pro BIG SUR not working as well the same error which means

bimalkjha commented 1 year ago

@a473000 The root cause of this issue on M1 Chip system is a the file pointed out by /usr/lib/libstdc++.6.dylib is deleted. So, if you have installed gcc and you copy /usr/local/lib/gcc/8/libstdc++.6.0.9.dylib as /usr/lib/libstdc++.6.0.9.dylib, the issue should get resolved. Pick up the libstdc++.6.0.9.dylib from your installed version of gcc. If gcc is not installed, install it first. Thanks.

a473000 commented 1 year ago

Thank you for your replay and time, perhaps you would't mind write down steps to do that in terminal so people could follow, because perhaps that is there solution but I have no idea how to fix that, despite you telling me . I will try. how to check gcc version ? how to pick it up ? thank you (base) przemyslawczekaj@Przemyslaws-Mac-mini ~ % gcc --version Apple clang version 14.0.0 (clang-1400.0.29.202) Target: arm64-apple-darwin22.1.0 Thread model: posix InstalledDir: /Library/Developer/CommandLineTools/usr/bin what to do now ? Thank You

bimalkjha commented 1 year ago

@nanthakumaran-s Uninstall and reinstall ibm_db after deleting site_packages\clidriver directory. Let us know if issue get resolved. Thanks.

a473000 commented 1 year ago

Hi thanks for all the anwsers this is how it looks: so Apple M1 Ventura , anaconda envi Jupiter Labs used to execute I have reinstall it ibm_db the same I have used this code !pip install --force-reinstall ibm_db ibm_db_sa - this is from coursera support output exactly the same. macbook pro (intel) BigS the same enviro output same windows 10 on macbook pro anaconda JLabs used and Jnotebooks ibm imports well, but I use %load_ext I het this is not ipthon module or something like this.( i Can get specific if you need )

So final point i must be doing something wrong or use the code wrong as nothing happens and I get the same result.

also I have brew o I can see it but this is where my knowledge ends whenit comes to it. Thank You

bimalkjha commented 1 year ago

@a473000 Have fresh installation of ibm_db. Then type python and enter to get python prompt. Then type import ibm_db and enter. If it works without any error, then you can run any python test program that imports ibm_db, it should work. For ibm_db_sa related issue, you need to open issue here: https://github.com/ibmdb/python-ibmdbsa/issues Thanks.

nanthakumaran-s commented 1 year ago

UPDATE ABOUT THIS ISSUE

Thanks for the support. I have experimented with many ways to overcome this issue and let me explain the possible ways for working this package in M1 and M2 macs and if they worked or not...

1. Docker container ❌

Created a docker container with a flavour of ubuntu that can install ibmdb and expose API to the host that can run the commands passed to the container. As you have guessed, docker uses the underlying arm architecture and this will not work if you have installed docker for arm processors.

2. Fresh Install of Python for intel macs ❌

I have separated the python installation by having a fresh install of python for the x86 architecture. The problem here is not with python itself. It is because of the missing /usr/lib/libstdc++.6.dylib which is actually a file from GCC (Not sure why it is from GCC) as this package is using GCC to build the binaries. The possible action from here is to install GCC using homebrew right? Let me explain the other 2 possibilities

3. GCC installation in arm-specific homebrew ❌

As this version of homebrew only supports gcc@11 (Don't know why this happens and the previous versions are not supported) this still raises issues because the homebrew was installed within the arm architecture as this package requires x86-based architecture to run

Atlast x86 version of homebrew with x86 version of python ✅

As you have come to a point, you have to install the x86 version of homebrew and install gcc@8 (I have tried with gcc@11 but for some reason, it is too not working as expected) then use the x86 version of python and its corresponding pip package to have a successful compilation

STEPS:

  1. Install the x86 version of homebrew instead of the arm version
  2. Install the x86 version of python
  3. Install gcc@8 using the command brew install gcc@8
  4. Run your python scripts

NOTE: If it throws an error this file /usr/lib/libstdc++.6.dylib is missing. Go to the GCC folder in the x86 homebrew and copy libstdc++.6.0.9.dylib from there to the location where it is requiring it.

LogicLuminaryy commented 7 months ago

M1 MAC Steps to Install IBM DB and Support Docker RUN

Installation Steps:

Install Podman / Docker: