0

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

3
  • Why don't you put a proper Python 3.11 shebang as the first line of your Python script if that's the version it needs in order to run. Then you don't need to specify any Python version in your C#. Commented Jan 17, 2025 at 22:44
  • @MarkSetchell I don't have much jurisdiction on what I can do with the script. I've tried changing the shebang and it's a solution, but it's not good for long-time support. Commented Jan 20, 2025 at 14:35
  • @AaronPascua Please update your question with the output of the shell command set (trim to PATH, path, *py* or *pythin*. Also include the first line of the file at {cmd}. Commented Jan 21, 2025 at 23:20

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.