- Notifications
You must be signed in to change notification settings - Fork768
-
Environment
Details
This error occurs in virtualenv and conda, and has not been tested in other ways. (Initialized successfully in windows.)
stringwinPath=@"D:\tools\python310";stringlinuxPath="/opt/miniconda3/envs/py310";if(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)){stringpathToVirtualEnv=winPath;Runtime.PythonDLL=Path.Combine(pathToVirtualEnv,"python310.dll");PythonEngine.PythonHome=Path.Combine(pathToVirtualEnv,"python.exe");PythonEngine.PythonPath=@$"{pathToVirtualEnv}\Lib\site-packages;{pathToVirtualEnv}\Lib;{pathToVirtualEnv}\DLLs";}elseif(RuntimeInformation.IsOSPlatform(OSPlatform.Linux)){//VirtualenvvarpathToVirtualEnv="/opt/miniconda3/envs/py310";Runtime.PythonDLL=$"{pathToVirtualEnv}/lib/libpython3.10.so";varpath=Environment.GetEnvironmentVariable("PATH").TrimEnd(';');path=string.IsNullOrEmpty(path)?pathToVirtualEnv:path+";"+pathToVirtualEnv;Environment.SetEnvironmentVariable("PATH",path,EnvironmentVariableTarget.Process);Environment.SetEnvironmentVariable("PATH",pathToVirtualEnv,EnvironmentVariableTarget.Process);Environment.SetEnvironmentVariable("PYTHONHOME",pathToVirtualEnv,EnvironmentVariableTarget.Process);Environment.SetEnvironmentVariable("PYTHONPATH",$"{pathToVirtualEnv}/lib/python310.zip;{pathToVirtualEnv}/lib/python3.10;{pathToVirtualEnv}/lib/python3.10/lib-dynload;{pathToVirtualEnv}/lib/python3.10/site-packages;~/.local/lib/python3.10/site-packages",EnvironmentVariableTarget.Process);varpythonpath=Environment.GetEnvironmentVariable("PYTHONPATH",EnvironmentVariableTarget.Process);;Console.WriteLine(pythonpath);PythonEngine.PythonHome=$"{pathToVirtualEnv}/bin/python";PythonEngine.PythonPath=pythonpath;}else{Console.WriteLine("This OS is not support");return;}PythonEngine.Initialize(); |
BetaWas this translation helpful?Give feedback.
All reactions
Oh my god!
It's a mistake.
We must use ":" instead of ";"
string winPath = @"D:\tools\python310"; string linuxPath = "/opt/miniconda3/envs/py310"; if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { string pathToVirtualEnv = winPath; Runtime.PythonDLL = Path.Combine(pathToVirtualEnv, "python310.dll"); PythonEngine.PythonHome = Path.Combine(pathToVirtualEnv, "python.exe"); PythonEngine.PythonPath = @$"{pathToVirtualEnv}\Lib\site-packages;{pathToVirtualEnv}\Lib;{pathToVirtualEnv}\DLLs"; } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))…Replies: 3 comments 1 reply
-
The reason for not accepting the answer is that there is a question in the python environment. |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
I had a similar issue, but a completely different environment, so I'm not sure if it applies. By default, pythonnet works with the .NET Framework environment, not core. Instructions for loading core: In my environment that alone isn't enough, because some of my dependencies could work with .NET 6 or 7, but there was no directive either way. My options were to load the .NET 7 runtuime or add in a reference to the runtimeconfig. You're running out of a .NET 6 application, so I would think the runtimeconfig.json for your app would be used? |
BetaWas this translation helpful?Give feedback.
All reactions
-
PythonPath, We must use ":" instead of ";" in Linux |
BetaWas this translation helpful?Give feedback.
All reactions
👍 2
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
Oh my god! |
BetaWas this translation helpful?Give feedback.
All reactions
This discussion was converted from issue #2216 on August 09, 2023 07:01.