# Python 3 support

**URL:** <https://mworks.discourse.group/t/python-3-support/310>\
**Category:** Support\
**Created:** [November 20, 2017, 3:45pm UTC](https://mworks.discourse.group/t/python-3-support/310 "2017-11-20T15:45:02Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [November 20, 2017, 3:45pm UTC](https://mworks.discourse.group/t/python-3-support/310/1 "2017-11-20T15:45:02Z")

</div>

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](https://docs.python.org/3/c-api/stable.html) 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](https://mworks.github.io/documentation/0.8/components/python_file_resource.html) and [run\_python\_file](https://mworks.github.io/documentation/0.8/components/run_python_file.html)/[run\_python\_string](https://mworks.github.io/documentation/0.8/components/run_python_string.html) 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

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [November 21, 2017, 6:00pm UTC](https://mworks.discourse.group/t/python-3-support/310/2 "2017-11-21T18:00:01Z")

</div>

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/) [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

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [July 26, 2018, 2:10pm UTC](https://mworks.discourse.group/t/python-3-support/310/3 "2018-07-26T14:10:21Z")

</div>

Hi Mark,

Thanks for sharing the link to [python3statement.org](http://python3statement.org). I hadn’t seen it previously.

As of the current [nightly build](https://mworks.github.io/downloads/), 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

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [July 26, 2018, 2:44pm UTC](https://mworks.discourse.group/t/python-3-support/310/4 "2018-07-26T14:44:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [July 27, 2018, 2:49pm UTC](https://mworks.discourse.group/t/python-3-support/310/5 "2018-07-27T14:49:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [August 6, 2018, 7:37pm UTC](https://mworks.discourse.group/t/python-3-support/310/6 "2018-08-06T19:37:12Z")

</div>

Got it - thanks.  
Mark

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [July 19, 2022, 9:43pm UTC](https://mworks.discourse.group/t/python-3-support/310/7 "2022-07-19T21:43:28Z")

</div>

Closed on July 19, 2022, 9:43pm UTC


