Revit could not complete the external command

I am trying to export simple data from some of my scripts in CSV format. I added a simple test Python code to both Python and Dynamo test tools, which export the CSV. It works without any problem for the Python tool. However, when I first ran the Dynamo tool with pyRevit, running the Python tool afterward triggers the error “Revit could not complete the external command.” Am I missing something here?
This Is the code I used in both dyn and py files:
import csv
import datetime

data = [
[“Name”, “Age”, “City”],
[“Alice”, 30, “New York”],
[“Bob”, 25, “Los Angeles”],
[“Charlie”, 35, “Chicago”]
]

directory_path = r’P:\Operations\Drawing Resources\Revit\2024-All CSV files’

now = datetime.datetime.now()
timestamp = now.strftime(“%Y-%m-%d_%H-%M-%S”)

X = ‘example_variable’

file_name = f’{timestamp}_{X}.csv’
file_path = f’{directory_path}\{file_name}’

with open(file_path, mode=‘w’, newline=‘’) as file:
writer = csv.writer(file)
writer.writerows(data)

image

1 Like

As you are using cpython you should check @ErikFrits video about importing modules:

Or as mentioned in

CPython engine is under active development and might be unstable. If you want to use python for development, it is preferred to use IronPython. CPython should only be used when accessing C-based python packages (e.g. numpy, scipy) is necessary.

1 Like

Thank you for your reply. Converting to IronPython solved the issue!