less than 1 minute read

I recently needed to use numpy in a Fusion 360 python script, and was surprised by how tricky it is to manage python environments w/ Fusion360.

The recommended method from Autodesk involves installing a local version of the desired module alongside your script. This method is ok for simple native python modules, but struggles in more complex scenarios. More specifically, using local import paths disturbs inter-module dependencies and often breaks with complex modules containing compiled code (ex: numpy).

The easiest solution I came up with was using Fusion360’s registered python and environment to handle the install by executing from a shell within Fusion360 itself. A bit hacky, but works:

First open the “Text Commands View” in Fusion360. You can find it under File->View->Show Text Commands:

placeholder

Enter the following commands to install a module (ex: numpy):

import sys
import subprocess
subprocess.check_call([sys.executable, "-m", "pip", "install", "--upgrade", "numpy"])

Make sure the py radio button is enabled in the bottom right of the “Text Commands View”

placeholder

Now you can use that module in scripts/add-ins as normal. For example:

import numpy as np

Categories:

Updated:

Comments