Python 3 support

Hi Mark,

As of the current nightly build, the Python “mworks” package (/Library/Application Support/MWorks/Scripting/Python/mworks) fully supports both Python 2.7 and Python 3.6. Usage is identical regardless of which Python version you use.

I had hoped to use Python 3’s stable ABI in order to support all versions after and including 3.2. Unfortunately, Boost.Python makes extensive use of non-stable ABI elements, so this wasn’t possible.

Python code that runs inside MWServer (via Python file resources and run_python_file/run_python_string actions) still uses only Python 2.7. The issue here is that it isn’t possible (or, at least, it isn’t safe) to embed multiple versions of Python in a single application. We could probably make the desired Python version an option in the MWorks installer, but I haven’t done any work on that.

Also, the client’s Python bridge is still hard-coded to launch Python 2.7. However, fixing that will be as simple as adding a field for the desired Python executable.

Cheers,
Chris

Hi Chris,

This is great, thanks. I’ll probably be able to test in the next 2 months.

As for Py3 inside MWServer, you may have seen this schedule for scientific Python.
http://www.python3statement.org/ http://www.python3statement.org/
Perhaps there should be a point that you cut over, or add Py3 support to the installer.
We’ll probably be ready to try cutting over to Py3 inside MWServer in the next 6 months, but could wait longer.

Mark

Hi Mark,

Thanks for sharing the link to python3statement.org. I hadn’t seen it previously.

As of the current nightly build, MWorks’ Python plugin (which implements Python resource files, the “run_python” actions, and the py_call/py_eval functions) now includes its own copy of Python 3.7. Specifically, it embeds libpython, the standard library (both pure Python code and compiled extensions), and NumPy. All MWorks components that execute Python code inside MWServer now use this bundled Python. Also, I’ve ported the Python plugin to iOS, so all of the aforementioned components will be available there in the next release.

The Python “mworks” package (which supports event-file I/O and conduits) is now built against Python 3.7 as well (in addition to 2.7). To use it, you’ll still need to install Python 3.7 yourself, as the version bundled with the Python plugin doesn’t include a Python executable and isn’t intended to be used as a standalone Python installation.

If you have any questions, please let me know!

Cheers,
Chris

Hi Chris,

Thanks. Sounds great.

One question: How can we install packages in the bundled python? In the past we have needed some serialization packages and I think we still rely on them. Is this just a matter of pointing pip to the site-packages directory of the bundled Python?

Mark

Hi Mark,

How can we install packages in the bundled python?

There’s no site-packages directory associated with the bundled Python. To use additional packages, you’ll need to install them somewhere on your machine and then explicitly add the installation directory to sys.path in the Python code that runs inside MWorks.

I’d probably use pip’s --user option to install in to my user site-packages, e.g.

pip3 install --user some_package

Then, I’d add my user site-packages to the end of sys.path in the Python code I want to run in MWorks. You can get the path from the site package:

$ python3 -c 'import site ; print(site.USER_SITE)'
/Users/cstawarz/Library/Python/3.7/lib/python/site-packages

But that’s just one option. You can install the packages anywhere that makes sense to you.

Chris

Got it - thanks.
Mark