Python packages for mworks

Hi Chris,
I can’t seem to find the answer to this in the discussion/user manual, but apologies if it’s a redundant question.

I’m trying to call a python from mworks that includes some packages (pandas) that apparently are not included in the mworks-bundled python. I tried adding the path within the python file*, but can’t seem to get it work**. Any thoughts?

include code:*
import sys
PYTHONPATH_CONDA = ‘/Users/rishi/anaconda/envs/py27/lib/python2.7/site-packages/’
sys.path.insert(0, PYTHONPATH_CONDA)
import pandas as pd

error**:
ImportError: dlopen(/Users/rishi/anaconda/envs/py27/lib/python2.7/site-packages/pandas/_libs/tslib.so, 2): Symbol not found: _PyCObject_Type
Referenced from: /Users/rishi/anaconda/envs/py27/lib/python2.7/site-packages/pandas/_libs/tslib.so
Expected in: flat namespace
in /Users/rishi/anaconda/envs/py27/lib/python2.7/site-packages/pandas/_libs/tslib.so

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/var/folders/xn/2zkbn8994kngz51j2kzrfh980000gn/T/MWorks/Experiment Cache/Users_rishi_Dropbox_(MIT)_JazLab_rr_mwk_PONG_from_validation100.mwel/tmp/PONG_utils.py”, line 5, in
import pandas as pd
File “/Users/rishi/anaconda/envs/py27/lib/python2.7/site-packages/pandas/init.py”, line 35, in
“the C extensions first.”.format(module))
ImportError: C extension: dlopen(/Users/rishi/anaconda/envs/py27/lib/python2.7/site-packages/pandas/_libs/tslib.so, 2): Symbol not found: _PyCObject_Type
Referenced from: /Users/rishi/anaconda/envs/py27/lib/python2.7/site-packages/pandas/_libs/tslib.so
Expected in: flat namespace

Hi Chris,

Feel free to ignore this – it was due to mworks python not supporting c-types, and your solution here worked.

Thanks,

Hi Rishi,

The problem is that MWorks bundles Python 3.7, but you’re trying to import a module that’s compiled against Python 2.7. Specifically, it’s failing to load because the module expects to find a symbol (_PyCObject_Type) that doesn’t exist in Python 3.7.

The solution is to use a version of pandas built against Python 3.7.

it was due to mworks python not supporting c-types, and your solution here worked.

That’s good, although I don’t know why it worked, since the initial problem wasn’t related to ctypes. Maybe pandas tries ctypes first, then falls back on the compiled module only if that fails?

Chris