You can add pip
and external libraries to the Dynamo python interpreter using the script in my post here Openpyxl module
If that is not your preferred method -or- you are using a more recent version of python and associated modules you could run a script that calls another version of python and use argparse
library to pass arguments
import subprocess
def runpy(pyexe, script):
"""
Run different version of python inside Dynamo
Script is python list or string of script (including path)
with command line arguments. Beware of spaces in file paths
"""
if pyexe:
comm = [pyexe]
if isinstance(script, str):
comm += script.split()
elif isinstance(script, list):
comm += script
return subprocess.run(comm, capture_output=True, shell=True)
pyexe = IN[0]
script = IN[1]
result = runpy(pyexe, script)
OUT = result.stdout.decode(), result.stderr.decode()
So IN[0]
path to python like this C:/Users/<username>/AppData/Local/Programs/Python/Python311/python.exe
And a basic script example with IN[1]
as "C:/temp/test_script.py a b c"
import argparse
import platform
print(platform.python_version())
parser = argparse.ArgumentParser()
parser.add_argument("echo", nargs="*")
args = parser.parse_args()
if args.echo:
print(args.echo)
else:
print("No arguments here")
Result