Cannot Import Pillow Module in Python API

Cannot Import Pillow Module in Python API

jsormaz
Advocate Advocate
655 Views
1 Reply
Message 1 of 2

Cannot Import Pillow Module in Python API

jsormaz
Advocate
Advocate

I am creating an API the generates labels and sends them to a label printer. I have it working in a test environment, but when I try to bring it into the Fusion API, I cannot make use of the Module "Pillow".  (https://pypi.org/project/Pillow/)

 

If I try to copy the PIL folder from site-packages and paste into a subfolder of my Add in, it mostly works but then fails at:

 

ImportError: cannot import name '_imaging' from '__main__C%3A%2FUsers%2Fjsorm%2FAppData%2FRoaming%2FAutodesk%2FAutodesk%20Fusion%20360%2FAPI%2FAddIns%2FAutoOpenTest%2FAutoOpenTest_py.Modules.PIL' (C:/Users/jsorm/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/AddIns/AutoOpenTest\Modules\PIL\__init__.py)

 

 

it seems that "_imaging" is a C module, and won't load. 

 

Is there a way for me to natively install pillow to the fusion python modules?

 

I'm no expert, I'm hacking my way through this so please bear with me 🙂

Instagram:
@sonsofsormaz
0 Likes
Accepted solutions (1)
656 Views
1 Reply
Reply (1)
Message 2 of 2

jsormaz
Advocate
Advocate
Accepted solution

I got it to work by creating a separate "installation" script containing the following code. 

 

import sys
import subprocess

# implement pip as a subprocess:
subprocess.check_call([sys.executable, '-m', 'pip', 'install', 
'Pillow'])

 source: https://www.activestate.com/resources/quick-reads/how-to-install-python-packages-using-a-script/

Instagram:
@sonsofsormaz