Topics

IronPython with Anaconda 3.7

Ajay Kumar Wahi
 

Hello everyone,

 

For past few days I am trying to integrate python script into C# application using IronPython. I have Anaconda 3.7.4 installed on the machine. I have added IronPython 2.7.9 as a reference to the project.

The targeted .Net framework is 4.7.2.

 

I am getting exception message while executing python script.

 

 

Below is the C# function that is setting up python environment and executing script:

 

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 

ScriptEngine pythonEngine = IronPython.Hosting.Python.CreateEngine();

 

            ICollection<string> searchPaths = pythonEngine.GetSearchPaths();

            //string pythonInstallPath = Environment.GetEnvironmentVariable("Path");

            //searchPaths.Add(pythonInstallPath);

            //searchPaths.Add(@"C:\ProgramData\Anaconda3\libs");

            //searchPaths.Add(@"C:\ProgramData\Anaconda3\pkgs");

            searchPaths.Add(@"C:\ProgramData\Anaconda3\python37.zip");

            searchPaths.Add(@"C:\ProgramData\Anaconda3\DLLs");

            searchPaths.Add(@"C:\ProgramData\Anaconda3\Lib");

            searchPaths.Add(@"C:\ProgramData\Anaconda3");

            searchPaths.Add(@"C:\ProgramData\Anaconda3\Lib\site-packages");

            searchPaths.Add(@"C:\ProgramData\Anaconda3\Lib\site-packages\win32");

            searchPaths.Add(@"C:\ProgramData\Anaconda3\Lib\site-packages\win32\lib");

            searchPaths.Add(@"C:\ProgramData\Anaconda3\Lib\site-packages\pythonwin");

            searchPaths.Add(@"C:\ProgramData\Anaconda3\Lib\site-packages\IPython\extensions");

            pythonEngine.SetSearchPaths(searchPaths);

            ScriptSource pythonScript = pythonEngine.CreateScriptSourceFromFile(@"..\..\..\PythonScripts\QC_dummy_file.py");

            var scope = pythonEngine.CreateScope();

 

            object result = pythonScript.Execute(scope);

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 

 

Can anyone please share if there is any solution to this problem? Or if there is any specific version of .Net Framework or Anaconda or IronPython that works together?

 

Regards,

Ajay

 

This e-mail, including any attached files, may contain confidential and privileged information for the sole use of the intended recipient. Any review, use, distribution, or disclosure by others is strictly prohibited. If you are not the intended recipient (or authorized to receive information for the intended recipient), please contact the sender by reply e-mail and delete all copies of this message.

Alex Earl
 

You can't mix and match python versions. You would need a 2.7 version of Anaconda because 2.7 is the version of python that ItonPython currently implements.


On Sat, Dec 28, 2019, 17:38 Ajay Kumar Wahi <AjayKumar.Wahi@...> wrote:

Hello everyone,

 

For past few days I am trying to integrate python script into C# application using IronPython. I have Anaconda 3.7.4 installed on the machine. I have added IronPython 2.7.9 as a reference to the project.

The targeted .Net framework is 4.7.2.

 

I am getting exception message while executing python script.

 

 

Below is the C# function that is setting up python environment and executing script:

 

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 

ScriptEngine pythonEngine = IronPython.Hosting.Python.CreateEngine();

 

            ICollection<string> searchPaths = pythonEngine.GetSearchPaths();

            //string pythonInstallPath = Environment.GetEnvironmentVariable("Path");

            //searchPaths.Add(pythonInstallPath);

            //searchPaths.Add(@"C:\ProgramData\Anaconda3\libs");

            //searchPaths.Add(@"C:\ProgramData\Anaconda3\pkgs");

            searchPaths.Add(@"C:\ProgramData\Anaconda3\python37.zip");

            searchPaths.Add(@"C:\ProgramData\Anaconda3\DLLs");

            searchPaths.Add(@"C:\ProgramData\Anaconda3\Lib");

            searchPaths.Add(@"C:\ProgramData\Anaconda3");

            searchPaths.Add(@"C:\ProgramData\Anaconda3\Lib\site-packages");

            searchPaths.Add(@"C:\ProgramData\Anaconda3\Lib\site-packages\win32");

            searchPaths.Add(@"C:\ProgramData\Anaconda3\Lib\site-packages\win32\lib");

            searchPaths.Add(@"C:\ProgramData\Anaconda3\Lib\site-packages\pythonwin");

            searchPaths.Add(@"C:\ProgramData\Anaconda3\Lib\site-packages\IPython\extensions");

            pythonEngine.SetSearchPaths(searchPaths);

            ScriptSource pythonScript = pythonEngine.CreateScriptSourceFromFile(@"..\..\..\PythonScripts\QC_dummy_file.py");

            var scope = pythonEngine.CreateScope();

 

            object result = pythonScript.Execute(scope);

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 

 

Can anyone please share if there is any solution to this problem? Or if there is any specific version of .Net Framework or Anaconda or IronPython that works together?

 

Regards,

Ajay

 

This e-mail, including any attached files, may contain confidential and privileged information for the sole use of the intended recipient. Any review, use, distribution, or disclosure by others is strictly prohibited. If you are not the intended recipient (or authorized to receive information for the intended recipient), please contact the sender by reply e-mail and delete all copies of this message.