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!
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?
Yes, encrypting/hiding the code is exactly what I want to do here.
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.