With JavaScript, you can easily load 3rd libraries in relative path or even web repository. We have an article on that:
With Python, typically we run a setup to install the modules and the dependent modules this module relies on. As we have known, Fusion 360 builds a Python environment at
%AppData%/Local/webdeploy\production\<GUID of one main release>\Python.
In theory, you could setup your modules there. They will be deployed to \Python\Lib\site-packages\. The Python/lib folder is set to the system path on Fusion startup, so any packages located there should be found when imported from any script.
However, when Fusion is updated, it might update something of Python environment, particularly when it is a major release or even Fusion upgrades to a new version of Python. So there is a possibility that your script/add-in would not work because of the update. If you prefer to setup with the typical way, you will have to be at your own risk. The below is a forum post where our expert shared more detail comments:
https://forums.autodesk.com/t5/api-and-scripts/to-install-python-modules/td-p/5777176
Then, what you can do without typical way?
Since Fusion builds the Python environment, you can actually also use relative path to import the modules dynamically. So, put your modules in the folder of your script /add-in and write some lines at the top of the codes.
e.g. I am practicing Socket.IO with Fusion, so I firstly downloaded the package from and copied the folder socketIO_client in my add-in path. Then, in my script, I tried to import it
#import Fusion modules import adsk.core, adsk.fusion, traceback #import system modules import os, sys #get the path of add-in my_addin_path = os.path.dirname(os.path.realpath(__file__)) print(my_addin_path) #add the path to the searchable path collection if not my_addin_path in sys.path: sys.path.append(my_addin_path) #import socketIO according to the help of https://github.com/invisibleroads/socketIO-client from socketIO_client import SocketIO, LoggingNamespace
you might agree, life is so beautiful exactly because it is not so smoothly sometimes and we enjoy how to overcome the frustration with the code above, I got errors. It said, other modules are missing. Checking the setup.py, I found it indicates the required modules which are not available with Python Libs of Fusion.
REQUIREMENTS = [ 'requests', 'six', 'websocket-client', ]
So I need to download them and copy to my add-in path. Of course, I can run setup.py to let the code to download automatically and take the modules. but, even though I copied them, it still threw an error below. I scratched my head for a bit long time. In the meantime, I started to realize it is not an elegant way to debug in Fusion to check the issue of importing only. This is because Fusion does not provide detail information about an error. It is just a superficial information which would not be helpful.
So, I thought of testing importing by Python environment. I created a separate Python file and copied it to C:\temp. In this file, some lines are like:
#import system modules import os, sys #get the path of add-in #my_addin_path = os.path.dirname(os.path.realpath(__file__)) #hard coded the absolute path of my add-in my_addin_path = 'C:\\Users\\liangx\\AppData\\Roaming\\Autodesk\\Autodesk Fusion 360\\API\\AddIns\\RemoteDriveParam' print(my_addin_path) #add the path to the searchable path collection if not my_addin_path in sys.path: sys.path.append(my_addin_path) #import socketIO according to the help of https://github.com/invisibleroads/socketIO-client from socketIO_client import SocketIO, LoggingNamespace
then, in command line of OS, switch to Python environment at
%AppData%/Local/webdeploy\production\<GUID of one main release>\Python, run the script:
python "c:\temp\testimport.py"
Now, it shows more detail about the error, which clearly tells which file popped out the error. By this clue, I finally addressed the dependent modules and the importing works now. In fact, it was just a mistake how I put the module of six.