when I run a python module which imports ssl.py , error occurs . but it's ok to run the straight python.

5 ビュー (過去 30 日間)
the error information is: Python Error: ImportError: dlopen(/Users/garyzhang/anaconda2/lib/python2.7/lib-dynload/_ssl.so, 2): Symbol not found: _SSL_CTX_set_alpn_protos Referenced from: /Users/anaconda2/lib/python2.7/lib-dynload/_ssl.so Expected in: /Applications/MATLAB_R2016a.app/bin/maci64/libssl.1.0.0.dylib in /Users/anaconda2/lib/python2.7/lib-dynload/_ssl.so

採用された回答

Robert Snoeberger
Robert Snoeberger 2016 年 7 月 26 日
Your issue looks like a library conflict with MATLAB's version of libssl, based on the part of the error message that says, "Expected in: /Applications/MATLAB_R2016a.app/bin/maci64/libssl.1.0.0.dylib". Notice that the library is part of the installation for MATLAB R2016a.
A workaround to try is to set the dlopen flag to RTLD_NOW | RTLD_DEEPBIND [1], which can be done with Python's sys.setdlopenflags [2]. This workaround was successful in a similar library conflict [3].
Example
>> RTLD_NOW = 2;
>> RTLD_DEEPBIND = 8;
>> flag = bitor(RTLD_NOW, RTLD_DEEPBIND); % RTLD_NOW | RTLD_DEEPBIND
>> py.sys.setdlopenflags(int32(flag));
>> py.importlib.import_module('_ssl');
References
  1. http://linux.die.net/man/3/dlopen -- Search for "RTLD_DEEPBIND".
  2. https://docs.python.org/2/library/sys.html#sys.setdlopenflags
  3. https://www.mathworks.com/matlabcentral/answers/265247-importing-custom-python-module-fails#comment_338642
  1 件のコメント
Adam Roach
Adam Roach 2019 年 12 月 13 日
Hi Robert,
I'm having this same problem and trying to follow the workaround you described but the setdlopenflags line is throwing an exception:
Undefined variable "py" or class "py.sys.setdlopenflags".
I'm running Matlab R2018b, with python 3.7 on a windows 10 machine.

サインインしてコメントする。

その他の回答 (3 件)

Bo Li
Bo Li 2016 年 7 月 25 日
Did you call "import matlab.engine" before "import ssl"? What happens if you call "import ssl" before "import matlab.engine"?
It looks like the library used by your ssl.py is not compatible with the libssl shipped by MATLAB.

gary zhang
gary zhang 2016 年 7 月 25 日
Sorry. I didn't make the description clear. The issue happens when MATLAB calls the Python function which has a statement "import ssl". But this function can run without any exception on the straight Python.

gary zhang
gary zhang 2016 年 7 月 27 日
Hi Robert, thanks for you answer. I tried the workaround and it didn't fix my issue. Next, when I changed the value of RTLD_NOW and RTLD_DEEPBIND to 0, which means flag = 0, it worked. I am not very sure of fixing it completely, but no error occurs and I can get the results by running the codes. Thank you very much.
  2 件のコメント
Robert Snoeberger
Robert Snoeberger 2016 年 7 月 27 日
Hi Gary, Thanks for trying the workaround. That is very interesting that flag = 0 worked for you. I believe that 0 is the value of RTLD_LOCAL. Just curious, what was the value of flag before you set it to 0? You should be able to check with py.sys.getdlopenflags. For me, the value is 2.
gary zhang
gary zhang 2016 年 7 月 28 日
Yes. I had tied to get the dlopen flag before I modified it. The value was 2. Thereafter I set the RTLD_LAZY to 1 and RTLD_NOW to 0, so the value of flag is 1. It works too.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCall MATLAB from Python についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by