Environment :
I am running Visbrain module by Pythonnet. I had create a virtual environment named py36 in Anaconda 3. Anaconda 3 is in D drive. Trying to run below code in my c# program.
using (Py.GIL())
{
dynamic np = Py.Import("visbrain");
}
But it pops out an error which is
Python.Runtime.PythonException: 'ModuleNotFoundError : No module named 'visbrain''
stack trace :
Python.Runtime.PythonException
HResult=0x80131500
Message=ModuleNotFoundError : No module named 'visbrain'
Source=Python.Runtime
StackTrace:
i had visbrain under Lib\site-packages.
Tried Solution but did not success:
1) add PATH, PYTHONHOME in environment variable. PATH : D:\Anaconda3\envs\py36; PYTHONHOME : D:\Anaconda3\envs\py36;
2) pythonnet Embedding Python in .net example failing to load module added PYTHONPATH : D:\Anaconda3\envs\py36\Lib\site-packages;
===
i am strange that "numpy" module is also inside of the Lib\site-packages.
when i tried below example
dynamic np = Py.Import("numpy");
It is fine.
Would like to know what is the issue here and how to solve this, thank you.
according to https://github.com/pythonnet/pythonnet/wiki/Troubleshooting-on-Windows,-Linux,-and-OSX
it mentioned
"Unable to load DLL pythonXX": CPython is not installed, or not registered in %PATH% and %PYTHONHOME% environment variables. Alternatively set PythonEngine.PythonHome property before initializing Python runtime.
Instead of setting up PythonHome and Path manually, you set them up by coding.
before PythonEngine.Initialize();
just remember to set the PATH and PYTHONHOME, just as example
// Modify Path
string path = @"d:\Anaconda3\envs\py36;" + Environment.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.Machine);
// Set Path
Environment.SetEnvironmentVariable("PATH", path, EnvironmentVariableTarget.Process);
// Set PythonHome
Environment.SetEnvironmentVariable("PYTHONHOME", @"d:\Anaconda3\envs\py36", EnvironmentVariableTarget.Process);
// Set PythonPath
// ONLY SET THIS IF YOU ARE SURE WHAT YOU ARE DOING
Environment.SetEnvironmentVariable("PYTHONPATH", @"d:\Anaconda3\envs\py36\Lib", EnvironmentVariableTarget.Process);
I had a similar issue with Miniconda, apparently Python.NET does not work well with conda. See this answer: best is do reinstall python (without conda).
User contributions licensed under CC BY-SA 3.0