# Running CCX with python script

**URL:** <https://calculix.discourse.group/t/running-ccx-with-python-script/2743>\
**Category:** Uncategorized\
**Created:** [May 18, 2025, 9:38am UTC](https://calculix.discourse.group/t/running-ccx-with-python-script/2743 "2025-05-18T09:38:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paulo](https://avatars.discourse-cdn.com/v4/letter/p/bbce88/32.png) [@Paulo](https://calculix.discourse.group/u/Paulo)\
**Post date:** [May 18, 2025, 9:38am UTC](https://calculix.discourse.group/t/running-ccx-with-python-script/2743/1 "2025-05-18T09:38:38Z")

</div>

Hello, I am attempting to run CCX through a python script. I have written .inp files but unable to get ccx to run. Is there any documentation on this or any help?

---

<div class="post-metadata">

**Author:** ![rsmith](https://yyz2.discourse-cdn.com/free1/user_avatar/calculix.discourse.group/rsmith/32/1684_2.png) [@rsmith](https://calculix.discourse.group/u/rsmith)\
**Post date:** [May 18, 2025, 10:42am UTC](https://calculix.discourse.group/t/running-ccx-with-python-script/2743/2 "2025-05-18T10:42:22Z")

</div>

How are you calling ccx? What is the error you receive?

I would suggest to use `os.chdir()` to change the working directory of the Python process to the directory where the input file resides.  
Also make sure that the Python process has sufficient rights to write files in that directory, and that there is sufficient space on the device for the output files.

Try using `subprocess.run()`, like this;

```auto
import os
import subprocess as sp

os.chdir("location_of_input_file")
# Note: don't use foo.inp!
cp = sp.run(['ccx', '-i', 'foo'], capture_output=True, text=True)
if cp.returncode:
    print(f'call to ccx failed with error code {cp.returncode}')
    # Optionally, write the contents of cp.stdout and/or cp.strerr to a file.

```
