python packages for mworks

Rishi Rajalingham's Avatar

Rishi Rajalingham

20 Apr, 2019 04:31 PM

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 <module>
    import pandas as pd
  File "/Users/rishi/anaconda/envs/py27/lib/python2.7/site-packages/pandas/__init__.py", line 35, in <module>
    "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

  1. 1 Posted by Rishi Rajalingh... on 20 Apr, 2019 04:32 PM

    Rishi Rajalingham's Avatar

    Hi Chris,

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

    Thanks,

  2. Support Staff 2 Posted by Christopher Sta... on 20 Apr, 2019 04:40 PM

    Christopher Stawarz's Avatar

    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

  3. Christopher Stawarz closed this discussion on 23 Apr, 2019 02:46 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac