3

Every time I try to import a Python module from MATLAB (using py.importlib.import_module) it crashes. Sometimes the crash is immediate but other times it hangs for a while before crashing. Some modules seem to work, for example py.importlib.import_module('math') works fine, but py.importlib.import_module('random') causes a crash. I'm also unable to import custom modules.

This is the output of pyversion:

>> pyversion

       version: '3.7'
    executable: '/home/garden/anaconda3/bin/python3'
       library: '/home/garden/anaconda3/lib/libpython3.7m.so'
          home: '/home/garden/anaconda3'
      isloaded: 0

Any ideas how to fix this?

I'm not sure if this is helpful but I've narrowed it down to a particular line that's causing a crash, line 244 in the hashlib module:

240 for __func_name in __always_supported:
241     # try them all, some may not work due to the OpenSSL
242     # version not supporting that algorithm.
243     try:
244         globals()[__func_name] = __get_hash(__func_name)
245    except ValueError:
246         import logging
247         logging.exception('code for hash %s was not found.', __func_name)
2
  • This looks like something that the MathWorks should be helping you with. Did you contact your representative? Commented Jul 1, 2019 at 14:34
  • I submitted a support ticket and posted a similar question on the MathWorks site as well. Commented Jul 1, 2019 at 14:59

1 Answer 1

1

Per MathWorks support, this issue sometimes can arise when Python attempts to use the MathWorks version of libcrypto. This can be resolved by loading SSL using Python before attempting to import other modules. Adding these lines to the beginning of my MATLAB script seems to fix the problem for me:

py.sys.setdlopenflags(int32(10))
py.importlib.import_module('ssl')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.