Although not directly related to your question, I have been working on making some of my custom tools compatible in both ArcCatalog (not Map, that is, no map doc involved) and Pro. In ArcCatalog, it is an addin, but Pro does not allow python addins at lease yet so I will be using tools direct.
I have some custom modules that I load into each tool. I found that Python 3.5 has to load them in a different manner than 2.7. Although this is a work in progress (i.e. that is, my tool), and this has some path dependencies to be run from a script (not interactive window), I thought I would share this here. It does seem to help me access which version of python I am using, and then go from there. fwiw.
import time, os
import arcpy
def myMsgs(message):
arcpy.AddMessage(message)
print(message)
def isuncpath(a_path):
return os.path.splitunc(a_path)[0] != ''
arcpy.SetProduct("ArcInfo")
pathname, scriptname = (os.path.dirname(sys.argv[0]), os.path.basename(sys.argv[0]))
myMsgs("\n{0}\n {1} \n{0}\n".format(("*" * 38), scriptname))
myMsgs("path = {0}".format(pathname))
myMsgs("scriptname = {0}".format(scriptname))
scriptPath = r"\\<server>\<share>\Users\<user>\_MyPyAddins\dwcUpdateMasterFGDB_Pro\Install\scripts"
scriptPathforVer= (scriptPath.replace("\\", "/"))
myMsgs(scriptPathforVer)
myMsgs("Do both paths exist?\n scriptPath {0}\n scriptPathforVer {1}".format(arcpy.Exists(scriptPath), arcpy.Exists(scriptPathforVer)))
arcpy.env.scriptWorkspace = scriptPathforVer
sys.path.append(scriptPathforVer)
sys.path
pyVer = (sys.version[0:3])
myMsgs("the python version is: {0} ".format(pyVer))
if float(pyVer) == 3.5:
myMsgs("Using Pro, python version {0}".format(pyVer))
setVer = "3.5"
elif float(pyVer) < 3.0:
myMsgs("Using Desktop, python version {0}".format(pyVer))
setVer = "2.x"
else:
myMsgs("Software unknown, but using python version {0}".format(pyVer))
setVer = "other"
if setVer == "3.5":
import importlib.util
adfgUtilsPath = r"\\<server>\<share>\Users\<user>\_MyPyAddins\dwcUpdateMasterFGDB_Pro\Install\scripts\myUtils.py"
arcpy.Exists(adfgUtilsPath)
mymodList = ["myUtils", "gpdecorators", "StatusCheck", "sdeconnUtil"]
for mymod in mymodList:
try:
spec = importlib.util.spec_from_file_location(mymod, adfgUtilsPath)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
myMsgs("Successfully loaded {0}".format(mymod))
except:
myMsgs("-> Unable to load {0}".format(mymod))
elif setVer == "2.x":
from myUtils import *
from gpdecorators import *
from StatusCheck import *
from sdeconnUtil import *
scriptPath = sys.path[0]
arcpy.AddMessage("the scriptPath is: {0} ".format(scriptPath))
print("the scriptPath is: {0} ".format(scriptPath))