Sounds like you want to use relative paths to store the script that is associated with the Toolbox, if I understand the question properly. Right click on your Script in its Toolbox, go the General tab, check the "Store relative path names" option. From the help:
Using absolute paths, if you moved the toolbox from
D:\Tools\Toolboxes\Toolbox1 to a different disk, such as
E:\Final\Toolbox1 ArcGIS will find D:\Tools\Scripts\MyScript.py and everything will work fine. If, however, you use relative paths,
ArcGIS will not find the script and the tool will not work. The tool
dialog box will open, but when you execute, you'll get the error
message "Script associated with this tool does not exist." You will
have to open the tool's properties and enter the correct path to the
script. On the other hand, if you use relative paths, you can simply
copy the folder D:\Tools anywhere on anyone's computer and everything
will work. This won't work if you use absolute paths, because the
recipient could copy the folder to F:\NewTools and the path
D:\Tools\Scripts\MyScript.py won't exist on his or her computer.
PYTHONPATH
so you can import other modules, usesys.path
. If you're just trying to combine the working directory with a relative path, useos.path.join
.