Я хочу использовать exe-файл Python и dll Python из среды conda с именем «playground». >
Код довольно прост (и работает с использованием системного Python exe):
Код: Выделить всё
using Python.Runtime;
using System;
using System.Reflection;
using System.Reflection.PortableExecutable;
using System.Xml.Linq;
using static System.Formats.Asn1.AsnWriter;
string pythonDll = @"python310.dll";
Environment.SetEnvironmentVariable("PYTHONNET_PYDLL", pythonDll);
PythonEngine.Initialize();
PythonEngine.BeginAllowThreads();
RunScript("sqlite_unpack_interactive", "main");
static void RunScript(string scriptName, string methodName)
{
using (Py.GIL())
{
dynamic os = Py.Import("os");
dynamic sys = Py.Import("sys");
sys.path.append(@"C:\Users\gianmaria_c\OneDrive - Promau Srl\Code\CS\InterOps-Sqlite");
var pythonScript = Py.Import(scriptName);
var r = pythonScript.InvokeMethod(methodName);
}
}
Код: Выделить всё
Python path configuration:
PYTHONHOME = (not set)
PYTHONPATH = (not set)
program name = 'python'
isolated = 0
environment = 1
user site = 1
import site = 1
sys._base_executable = 'C:\\Users\\gianmaria_c\\OneDrive - Promau Srl\\Code\\CS\\InterOps-Sqlite\\bin\\Debug\\net6.0\\InterOps-Sqlite.exe'
sys.base_prefix = 'C:\\Users\\gianmaria_c\\AppData\\Local\\anaconda3'
sys.base_exec_prefix = 'C:\\Users\\gianmaria_c\\AppData\\Local\\anaconda3'
sys.platlibdir = 'lib'
sys.executable = 'C:\\Users\\gianmaria_c\\OneDrive - Promau Srl\\Code\\CS\\InterOps-Sqlite\\bin\\Debug\\net6.0\\InterOps-Sqlite.exe'
sys.prefix = 'C:\\Users\\gianmaria_c\\AppData\\Local\\anaconda3'
sys.exec_prefix = 'C:\\Users\\gianmaria_c\\AppData\\Local\\anaconda3'
sys.path = [
'C:\\Users\\gianmaria_c\\AppData\\Local\\anaconda3\\python310.zip',
'.\\DLLs',
'.\\lib',
'C:\\Users\\gianmaria_c\\OneDrive - Promau Srl\\Code\\CS\\InterOps-Sqlite\\bin\\Debug\\net6.0',
]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'
Current thread 0x00006f0c (most recent call first):
Я пробовал запустить скрипт из разных conda envs (с разными версиями Python), та же ошибка.
Я попробовал запустить скрипт из системного Python, PythonEngine.Initialize() работает.
что я делаю не так?< /п>
Подробнее здесь: https://stackoverflow.com/questions/791 ... nvironment