Importing a module from an embedded script tool?

413
3
03-31-2021 06:12 PM
GB_MattPanunto_GISS
Occasional Contributor

I have a script that I imported into a toolbox (.tbx), so the script file is now embedded. My question is, how do I import the modules from this embedded script file so that my imported script tools run without the "ModuleNotFoundError"?

 

Everything works fine if I don't import the script and just provide the path in the script tool properties, but I can't figure out how to get things working when the script file is embedded into the toolbox.

 

Thanks!

0 Kudos
3 Replies
DanPatterson
MVP Esteemed Contributor

Not sure why you want to import the script that is used to run the toolbox.  Embedding it, places it inside the tbx, there is no need to import it.  If you are importing other modules (aka, scripts) you can do that in the main script associated with the toolbox.

The safest layout is to create a folder with your tbx, main script and supporting scripts in it.

Are you attempting to encrypt/hide the source code for the main script? 


... sort of retired...
0 Kudos
GB_MattPanunto_GISS
Occasional Contributor

Yes, encrypting/hiding the code is exactly what I want to do here.

0 Kudos
DanPatterson
MVP Esteemed Contributor

include all your code in the py attached to the tbx and encrypt it or

use a pyt and encrypt it

EncryptPYT—ArcGIS Pro | Documentation

You can import toolboxes, list tools etc from arcpy as well... for example

ImportToolbox—ArcGIS Pro | Documentation

If you intend to use your code outside of the arcpy environment you will have to use one of the available encryption modules found on the web.

A good license is a better way of maintaining intellectual property rights. 

Examine the packages on GitHub for examples of how to maintain open code with preserved rights and even options for economic support for projects.

Be aware the nothing is fully secure.

 


... sort of retired...
0 Kudos