Когда я запускаю inversetest.py в приложении wpf, я получаю некоторые ошибкиC#

Место общения программистов C#
Anonymous
Когда я запускаю inversetest.py в приложении wpf, я получаю некоторые ошибки

Сообщение Anonymous »

Когда я запускаю код Python на C#, я получаю много ошибок из mycode.py, но в vscode он работает хорошо. Я использую любой способ типа python.net, железный Python, Process,... но он не работает:
private void Button_Click(object sender, RoutedEventArgs e)
{
string scriptPath = @"E:\TrainedModels\inversetest.py";
var result = RunPythonScript(scriptPath);

BitmapImage bitmap = new BitmapImage();
bitmap.BeginInit();
bitmap.UriSource = new Uri(result);
bitmap.EndInit();
Chart.Source = bitmap;
}

public static string RunPythonScript(string scriptPath)
{
ProcessStartInfo startInfo = new ProcessStartInfo
{
FileName = "\"C:\\Users\\PC 4\\AppData\\Local\\Programs\\Python\\Python312\\python.exe\"",
Arguments = scriptPath,
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true,
//WorkingDirectory = @"E:\TrainedModels"
};

using (Process process = new()
{
StartInfo = startInfo
})
{
process.Start();

var output = process.StandardOutput.ReadToEnd();
var error = process.StandardError.ReadToEnd();
process.WaitForExit();

if (!string.IsNullOrEmpty(error))
{
return $"Error: {error}";
}
return output;
}

Error: 2024-10-16 08:42:48.906422: I tensorflow/core/util/port.cc:153] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.

2024-10-16 08:42:51.055637: I tensorflow/core/util/port.cc:153] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.

2024-10-16 08:42:54.192569: I tensorflow/core/platform/cpu_feature_guard.cc:210] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.

To enable the following instructions: AVX2 AVX512F AVX512_VNNI FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.

Traceback (most recent call last):
File "E:\TrainedModels\inversetest.py", line 32, in
pre_Down=valve_model_Down.predict(X)
^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "C:\Users\PC 4\AppData\Local\Programs\Python\Python312\Lib\site-packages\keras\src\utils\traceback_utils.py", line 122, in error_handler
raise e.with_traceback(filtered_tb) from None
File "C:\Users\PC 4\AppData\Local\Programs\Python\Python312\Lib\concurrent\futures\_base.py", line 449, in result
return self.__get_result()

File "C:\Users\PC 4\AppData\Local\Programs\Python\Python312\Lib\concurrent\futures\_base.py", line 401, in __get_result
raise self._exception
^^^^

File "C:\Users\PC 4\AppData\Local\Programs\Python\Python312\Lib\concurrent\futures\thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
^^^^

File "C:\Users\PC 4\AppData\Local\Programs\Python\Python312\Lib\encodings\cp1252.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

UnicodeEncodeError: 'charmap' codec can't encode characters in position 19-38: character maps to


Подробнее здесь: https://stackoverflow.com/questions/790 ... ome-errors

Вернуться в «C#»