Visitar URL original
Py.Import("numpy") error:Original error was: cannot import name 'Sequence' from 'collections' (D:\ProgramData\anaconda3\Lib\collections\__init__.py) · Issue #2506 · pythonnet/pythonnet · GitHub
Skip to content

Py.Import("numpy") error:Original error was: cannot import name 'Sequence' from 'collections' (D:\ProgramData\anaconda3\Lib\collections\__init__.py) #2506

Description

@vc815

Environment

win11
python 3.10.9

Details

string pathToVirtualEnv = "D:\ProgramData\anaconda3";
Environment.SetEnvironmentVariable("PATH", pathToVirtualEnv, EnvironmentVariableTarget.Process);
Environment.SetEnvironmentVariable("PYTHONHOME", pathToVirtualEnv, EnvironmentVariableTarget.Process);
Environment.SetEnvironmentVariable("PYTHONPATH", $"{pathToVirtualEnv}\Lib\site-packages;{pathToVirtualEnv}\Lib", EnvironmentVariableTarget.Process);

Runtime.PythonDLL =$"{pathToVirtualEnv}\python310.dll";
PythonEngine.PythonHome = pathToVirtualEnv;
PythonEngine.PythonPath = $@"D:\ProgramData\anaconda3" +
$@";D:\ProgramData\anaconda3\Lib\site-packages" +
$@";D:\ProgramData\anaconda3\Lib;";
PythonEngine.Initialize();
using (Py.GIL())
{

 dynamic  np = Py.Import("numpy");《---------------------------
 Console.WriteLine(np.cos(np.pi * 2));

}

error:
Python.Runtime.PythonException:“

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.

We have compiled some common reasons and troubleshooting tips at:

https://numpy.org/devdocs/user/troubleshooting-importerror.html

Please note and check the following:

  • The Python version is: Python3.10 from "C:\Users\ufona\Desktop\WindowsFormsApp1\WindowsFormsApp1\bin\x64\Debug\WindowsFormsApp1.exe"
  • The NumPy version is: "1.23.5"

and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.

Original error was: cannot import name 'Sequence' from 'collections' (D:\ProgramData\anaconda3\Lib\collections_init_.py)
”

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions