Sunday, 4 February 2018

Packaging third-party libraries with Python Toolbox of ArcPy?


I wrote a Python Toolbox that uses libraries not included in ESRI's python (PIL, piexif).


But I can't run the toolbox on another computer that doesn't have those libraries. Since I don't want to install those libraries for every client that will be using the toolbox, is there a way to package the libraries with the toolbox to avoid any missing dependencies?



Answer



With pure Python packages you can simply place their module folders (cloned from git or wherever) into the same folder as your script files, and then in the properties for your tool check the box to access the scripts using relative paths (i.e. don't import them into the toolbox).


An example folder structure might be:


my_special_tools\

scripts\
third_party_module\
...
my_script.py
my_special_toolbox.tbx

Then you can distribute that entire folder to others.


However 3rd party packages that rely on C libraries have to actually be built, so unfortunately they can't be included this way. In this case it's probably easiest just to write a bat file that pip installs the necessary dependencies.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...