Aaron Pascua
Aaron Pascua

Reputation: 9

How to get CommandLineTools to use a different version of Python

I am using this C# code to call a python script.

Process.StartInfo = new ProcessStartInfo()
{
    FileName = @"/usr/bin/python3",
    Arguments = $@"{cmd} {args}", // cmd is the python script path
    RedirectStandardOutput = true,
    RedirectStandardError = true,
    UseShellExecute = false,
    CreateNoWindow = false
};

When I run my program, I get an OSError and noticed that the python interpreter is pointing to here: /Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/runpy.py

This error happens because this specific script being called runs on python3.11.

My question is, is there a way to properly change the version for CommandLineTools to use 3.11? I technically have a solution where I just copy the 3.11 folder into the ../../Versions folder and it works. This is not a good solution for me because I would have to do this for multiple systems. Is there another way around this? And why doesn't System.Diagnostics use the systems default python interpreter?

EDIT: I've learned that /Library/Developer/CommandLineTools come from Xcode. But how do I get my C# program to use usr/bin/python3 instead of ../CommandLineTools

Upvotes: 0

Views: 35

Answers (0)

Related Questions