Я нашел пример передачи параметров с помощью PythonNet, но не могу заставить его запускать мой код Python. Разработка на VS 2022. Я хочу (сначала) создать подкаталог, если он еще не существует. Путь и каталог должны быть переданы из C#.
protected void btnPythonTest_Click(object sender, EventArgs e)
{
// full path of python interpreter
string python = @"C:\Users\User\AppData\Local\Programs\Python\Python312\python.exe";
// python app to call
string myPythonApp = @"C:\OllamaDocs\MyTestPython.py";
// Paramters to send to Python (location of docs and Chroma for this user
string OllamDocsPath = @"C:\OllamaDocs\100\1\";
string OllamaChromaFilename = "Chroma_100_1B";
try
{
System.Diagnostics.ProcessStartInfo myProcessStart = new System.Diagnostics.ProcessStartInfo(python);
myProcessStart.UseShellExecute = true;
myProcessStart.RedirectStandardOutput = false;
// pass arguments to python script
myProcessStart.Arguments = myPythonApp + " " + OllamDocsPath + " " + OllamaChromaFilename;
System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
myProcess.StartInfo = myProcessStart;
myProcess.Start();
lblStatus.Text = myPythonApp + " Created " + OllamDocsPath + OllamaChromaFilename;
}
catch (Exception ex)
{
errorMessage = ex.Message;
lblStatus.Text = errorMessage;
}
} // end PythonTest()
Мой тестовый скрипт Python расположен в корне C: следующим образом (MyTestPython.py)
import os import sys
# Test Phase II
#Get args from C#
OllamaPath = sys.argv[0]
OllamaChroma = sys.argv[1]
# Define the directory for vector store persistence
#persist_directory = "C:\\OllamaDocs\\100\\1\\chroma_db_100-1"
persist_directory = OllamaPath
# Check if the vector store already exists
if not os.path.exists(persist_directory):
print("Creating new Chroma Directory " + persist_directory)
os.makedirs(persist_directory) else:
# Load the existing Chroma vector store
else:
# Load the existing Chroma vector store
print("path exists.")
Подробнее здесь: https://stackoverflow.com/questions/790 ... ot-running