在.NET中用PythonNet导入Pandas库报错“No Module named pandas”求助
.NET环境下使用PythonNet导入Pandas库报错"No Module named pandas"
在.NET环境中尝试通过PythonNet导入Pandas库时,始终触发错误提示No Module named pandas,以下是具体实现代码:
static void Main(string[] args) { // Set the path to the Python DLL Environment.SetEnvironmentVariable("PYTHONNET_PYDLL", @"C:\Users\username\AppData\Local\Programs\Python\Python311-32\python311.dll", EnvironmentVariableTarget.Process); // Initialize Python engine PythonEngine.Initialize(); // Use the Python Global Interpreter Lock (GIL) using (Py.GIL()) { var currentDirectory = Directory.GetCurrentDirectory(); var pythonFilePath = Path.GetFullPath(Path.Combine(currentDirectory, @"..\..\..\")); dynamic sys = Py.Import("sys"); sys.path.append(pythonFilePath); dynamic pd = Py.Import("pandas"); // Error at this line dynamic pythonScript = Py.Import("mypythonscript"); // Call the 'say_hello' function from the Python module dynamic result = pythonScript.return_dataset(); // Print the result Console.WriteLine(result); // Print the result Console.WriteLine(result); } // Shutdown Python engine PythonEngine.Shutdown(); }
已尝试以下方法但未解决问题:
- 查阅PythonNet官方文档,相关内容提及较少
- 咨询ChatGPT
内容的提问来源于stack exchange,提问作者Not Not One
相关产品推荐
相关产品推荐

