On Linux, the following pairs of commands both work:
$ python -c "import pymqi; pymqi.connect('QM1', 'DEV.APP.SVRCONN', 'localhost(1414)', user='xxx', password='xxx')" # command 1
$ bash -c "python -c \"import pymqi; pymqi.connect('QM1', 'DEV.APP.SVRCONN', 'localhost(1414)', user='xxx', password='xxx')\"" # command 2
On OSX, the first one succeeds and the second fails with this output:
TENDTraceback (most recent call last):
File "<string>", line 1, in <module>
File "/Users/wolfson/.local/share/virtualenvs/xxx-xWWWLtqs/lib/python3.11/site-packages/pymqi/__init__.py", line 3214, in connect
qmgr.connect_tcp_client(queue_manager or '', CD(), channel, conn_info, user, password)
File "/Users/wolfson/.local/share/virtualenvs/xxx-xWWWLtqs/lib/python3.11/site-packages/pymqi/__init__.py", line 1772, in connect_tcp_client
self.connect_with_options(name, **kwargs)
File "/Users/wolfson/.local/share/virtualenvs/xxx-xWWWLtqs/lib/python3.11/site-packages/pymqi/__init__.py", line 1747, in connect_with_options
raise MQMIError(rv[1], rv[2])
pymqi.MQMIError: MQI Error. Comp: 2, Reason 2009: FAILED: MQRC_CONNECTION_BROKEN
(Note that weird TEND prefix before Traceback. Weird!)
Not only that, but if I just run bash -c python and then do import pymqi; pymqi.connect('QM1', 'DEV.APP.SVRCONN', 'localhost(1414)', user='xxx', password='xxx') in the python shell, I get the same exception and the Python process itself exits.
This does not seem to happen when running the sample programs in /opt/mqm/samp/bin/.
I assume this has something to do with some OSX thing, but … what? and is there a workaround?
EDIT: This is not related to DYLD_LIBRARY_PATH. There is no nested build-time error:
% bash -c "pipenv run pip install pymqi"
Requirement already satisfied: pymqi in /Users/wolfson/.local/share/virtualenvs/xxx-xWWWLtqs/lib/python3.11/site-packages (1.12.10)
And it is (obviously) possible to import pymqi.pymqe in the nested shell.
This is due to the System Integrity Protection feature in macOS. Certain executables (including shell scripts) don't inherit DYLD_LIBRARY_PATH.
To see this is action:
echo $DYLD_LIBRARY_PATHbashecho $DYLD_LIBRARY_PATHDYLD_LIBRARY_PATHneeds to be set to pick up the MQ client runtime dynamic libraries that by default are in/opt/mqm/lib64