using Python

wangjing's Avatar

wangjing

10 Sep, 2019 12:05 AM

Hi Chris,
After I switched to version 0.9, I was not able to run script properly in the bundled python. Python stoped immediately without giving error. I suspect that the supporting libraries were not available to Mworks or there was version mismatch. Are there any ways to opt out and use non-mworks Python? I am much comfortable working and debugging in my old Anaconda environment. Thank you very much!

  1. Support Staff 1 Posted by Christopher Sta... on 10 Sep, 2019 01:49 PM

    Christopher Stawarz's Avatar

    Hi Jing,

    In MWorks 0.9, the embedded Python version (i.e. the Python that executes the run_python_file and run_python_string actions) changed from 2.7 to 3.7. If your Python script is no longer working in MWorks 0.9, then you're probably hitting one or more of the following issues:

    1. Your script uses syntax that's no longer valid in Python 3.
    2. Your script uses a standard-library module that's no longer available in Python 3.
    3. Your script depends on compiled, third-party extensions (e.g. installed via Anaconda) that are built against Python 2.7.

    Issue 3 is the easiest to check and remedy. Just make sure that you're using the Python 3.7 version of Anaconda.

    If the problem is with your script itself, then the 2to3 tool should help with any necessary updates.

    Cheers,
    Chris

  2. 2 Posted by wangjing on 10 Sep, 2019 04:16 PM

    wangjing's Avatar

    Hello Chris,
    Thank you for the prompt reply. I will adapt to python 3.7 one way or another.
    This maybe a separate but related question. The reason I updated from 0.8 to 0.9 and later ones is because I have updated macOS to Mojave that causes MWServer 0.8 stucks at loading, same encounter as described in previous inquiry<https://mworks.tenderapp.com/discussions/problems/388-mwserver-hang> . Is there a fix to the deadlock issue in version 0.8 with new mac OS. Sorry if this is an unreasonable request.

    Thanks again!

    - Jing

  3. Support Staff 3 Posted by Christopher Sta... on 10 Sep, 2019 06:45 PM

    Christopher Stawarz's Avatar

    Is there a fix to the deadlock issue in version 0.8 with new mac OS.

    No. If you need that fix, you have to use MWorks 0.9.

    Chris

  4. 4 Posted by wangjing on 11 Sep, 2019 02:48 PM

    wangjing's Avatar

    Hi Chris,
    MWorks uses mac's built-in python. right? could you please inform how to make site-packages installed under conda accessible to python script called in mserver conduit? Thank you!

  5. Support Staff 5 Posted by Christopher Sta... on 11 Sep, 2019 04:35 PM

    Christopher Stawarz's Avatar

    Hi Jing,

    could you please inform how to make site-packages installed under conda accessible to python script called in mserver conduit?

    Do you mean a Python script called via run_python_file? If so, then you need to add the following to your script, before it attempts to import any Anaconda packages:

    import sys
    sys.path.append('/Users/jing/anaconda3/lib/python3.7/site-packages')
    

    The actual path string may be different, depending on where and how you've installed Anaconda.

    If you're actually running your script via a server-side conduit, then MWorks has no control over how it's executed. You launch the script yourself, using the Python interpreter of your choice, and MWorks interacts with it via inter-process communication.

    MWorks uses mac's built-in python. right?

    In MWorks 0.8, the Python actions used macOS' built-in Python. However, they don't in MWorks 0.9. Instead, MWorks embeds its own copy of Python. (The macOS Python is still at version 2.7.)

    Cheers,
    Chris

  6. 6 Posted by wangjing on 11 Sep, 2019 05:42 PM

    wangjing's Avatar

    Hi Chris, I misunderstood. It must be the later case. I am running a script via Python script bridge.
    The confusion part is that error msg reported in the bridge console is not present in the anaconda environment. It makes hard to find out what's going on. My application is that python does heavy computing on its own and periodically sends update to mworks' variables. what is your recommendation?
    Thank you again!

  7. Support Staff 7 Posted by Christopher Sta... on 11 Sep, 2019 05:44 PM

    Christopher Stawarz's Avatar

    Could I stop by your office to see what's happening?

    Chris

  8. 8 Posted by wangjing on 11 Sep, 2019 08:03 PM

    wangjing's Avatar

    Hi Chris,

    The python seems working now after unistalling and installing opencv, and i have also changed path in the bash_profile. Although i am not completely sure which one helped.
    I left MIT and found MWorks still is essential part of research, thanks to your service. I really appreciate it, and will contact you via if more problems.
    - Jing

  9. wangjing closed this discussion on 12 Sep, 2019 12:19 AM.

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