You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MacOS导入pymqi报错:Library not loaded: @rpath/libmqic_r.dylib

Fixing ImportError: Cannot load @rpath/libmqic_r.dylib with pymqi on MacBook

Hey there, let's work through this pymqi import error step by step—since you're new to Python-related tools, I'll break everything down into simple, actionable steps.

First, let's recap what we know: you've got IBM MQ running via Docker, installed the IBM MQ macOS dev toolkit, successfully installed pymqi with pip, but hitting an ImportError when trying to import it. The libmqic_r.dylib file exists at /opt/mqm/lib64 and other paths, but the Python interpreter can't find it via the @rpath reference.

Here are the most likely fixes to try in order:

1. Set the correct dynamic linker environment variables

The @rpath in the error means the macOS dynamic linker needs explicit paths to find the MQ libraries. Let's add the MQ lib path to your shell's environment:

For Bash users:

# Add the path to your bash profile
echo 'export DYLD_LIBRARY_PATH=/opt/mqm/lib64:$DYLD_LIBRARY_PATH' >> ~/.bash_profile
echo 'export MQ_INSTALL_PATH=/opt/mqm' >> ~/.bash_profile

# Reload the profile to apply changes
source ~/.bash_profile

For Zsh users (default on newer MacBooks):

# Add the path to your zshrc
echo 'export DYLD_LIBRARY_PATH=/opt/mqm/lib64:$DYLD_LIBRARY_PATH' >> ~/.zshrc
echo 'export MQ_INSTALL_PATH=/opt/mqm' >> ~/.zshrc

# Reload the config to apply changes
source ~/.zshrc

After running this, close and reopen your terminal, then try importing pymqi again.

2. Verify pymqi is using your correct Python environment

Sometimes pip installs packages to a different Python version than the one you're running. Let's confirm consistency:

# Check which Python you're running
which python

# Check which pip is associated with it
which pip

If these paths don't match (e.g., one is from /usr/bin/ and the other from /usr/local/bin/), reinstall pymqi using the Python module to ensure it goes to the right place:

python -m pip install --force-reinstall pymqi

If the environment variable fix doesn't work, we can link the MQ library to a directory the dynamic linker checks by default (like /usr/local/lib):

sudo ln -s /opt/mqm/lib64/libmqic_r.dylib /usr/local/lib/libmqic_r.dylib

Enter your admin password when prompted, then restart your terminal and test the import again.

4. Check library permissions and dependencies

Make sure your user has read access to the library file:

ls -l /opt/mqm/lib64/libmqic_r.dylib

If you see permissions like -rwx------, fix them with:

sudo chmod +r /opt/mqm/lib64/libmqic_r.dylib

Also, let's check if libmqic_r.dylib depends on other libraries that might be missing. Run this command on the library itself:

otool -L /opt/mqm/lib64/libmqic_r.dylib

Look for any other entries marked with @rpath—if those libraries are also in /opt/mqm/lib64, our earlier DYLD_LIBRARY_PATH setting should cover them. If not, you'll need to add their paths to the variable too.

5. Test the import in a fresh terminal session

Sometimes old environment variables linger in existing terminal windows. Close all open terminals, open a new one, then run:

import pymqi
print("Success! pymqi imported correctly.")

内容的提问来源于stack exchange,提问作者SQLGobbleDeGook

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.12 04:32:05