Skip to content

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

Closed

Description

@nanthakumaran-s

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

Activity

  1. bimalkjha commented on Oct 18, 2022

    @bimalkjha
    Member

    @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.

  2. nanthakumaran-s commented on Oct 18, 2022

    @nanthakumaran-s
    Author

    @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 ??

  3. bimalkjha commented on Oct 18, 2022

    @bimalkjha
    Member

    @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.

  4. nanthakumaran-s commented on Oct 23, 2022

    @nanthakumaran-s
    Author

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

    image

  5. bimalkjha commented on Oct 24, 2022

    @bimalkjha
    Member

    @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.

  6. rajpatel794 commented on Nov 1, 2022

    @rajpatel794

    @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?

  7. rajpatel794 commented on Nov 1, 2022

    @rajpatel794

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

  8. jonathanloske commented on Nov 1, 2022

    @jonathanloske
    Contributor

    @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.

  9. bimalkjha commented on Nov 1, 2022

    @bimalkjha
    Member

    @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.

  10. bimalkjha commented on Nov 5, 2022

    @bimalkjha
    Member

    @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.

  11. bimalkjha commented on Nov 9, 2022

    @bimalkjha
    Member

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

  12. bimalkjha commented on Nov 19, 2022

    @bimalkjha
    Member

    @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.

  13. nanthakumaran-s commented on Nov 24, 2022

    @nanthakumaran-s
    Author

    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.

  14. LogicLuminaryy commented on Mar 5, 2024

    @LogicLuminaryy
    Contributor

    M1 MAC Steps to Install IBM DB and Support Docker RUN

    Installation Steps:

    Install Podman / Docker:

    • Podman: Follow the instructions provided on the official Podman website to install Podman on your M1 Mac.
    • Docker: Alternatively, you can install Docker using the native Apple Silicon version or the Rosetta-translated Intel version. Choose the method that best fits your requirements.

    Install Intel Version of Python:

    1. Download and install the Intel version of Python 3.8 from the official Python website.
    2. After installation, ensure that you set the interpreter to Python 3.8 in your development environment.

    Configuration Steps:

    Configure Docker for M1:

    • For M1 Macs, ensure compatibility by specifying the platform architecture during Docker build commands:
      docker build -t <image_name> . --platform=linux/amd64
      Alternatively, if you're using Podman:
      podman build -t <image_name> . --platform=linux/amd64

    Build Docker Image (Intel):

    • If you're using an Intel Mac or running Docker with Rosetta translation, use the following command to build your Docker image:
      docker build -t <image_name> .

    Additional Notes:

    • These steps are tailored for M1 Macs to ensure seamless installation and configuration of IBM DB and Docker support.
    • Verify that your Dockerfile and any dependencies are compatible with the specified platform architecture.
      Follow these steps carefully to set up IBM DB and Docker support on your M1 Mac environment. If you encounter any issues or have further questions, feel free to seek assistance from the community or relevant support channels.
      Happy coding!
  15. bimalkjha commented on Dec 30, 2024

    @bimalkjha
    Member

    @LogicLuminaryy @rajpatel794 @nanthakumaran-s @a473000 We have released ibm_db v3.2.5 with native installation support for MacOS Silicon Chip system and no need to use the emulated environment with x86_64 python on M1 chip system. Please install latest version of ibm_db and verify. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions