0

I am trying to run a simple python code using C# using Iron Python Package.

Why it throws the below error (attached in screenshot)

The code runs fine if i don't import libraries,

but it throws error after importing libraries all tough i have stored required libraries in defined folders

import pandas as pd
print("HIIII")
print(a+b)
using IronPython.Hosting;//for DLHE 
using Microsoft.Scripting; 
using Microsoft.Scripting.Hosting;//provides scripting abilities comparable to batch files 
using System; 
using System.Diagnostics; 
using System.IO; 
using System.Net; 
using System.Net.Sockets; 
using System.Threading.Tasks; 
using IronPython.Runtime; 
using IronPython; 

class Hi {     
    private static void Main(string[] args) {
        var engine = Python.CreateEngine();
        var searchPaths = engine.GetSearchPaths();
        searchPaths.Add(@"C:\Users\nayan.nirvikar\source\repos\PythonCSharpIntegration\Lib");
        engine.SetSearchPaths(searchPaths);
        var scope = engine.CreateScope();
        scope.SetVariable("a", 10);
        scope.SetVariable("b", 20);

        var source = engine.CreateScriptSourceFromFile(@"C:\Users\nayan.nirvikar\Downloads\sample_script.py");
        var compilation = source.Compile();
        var result = compilation.Execute(scope);
        foreach (var varName in scope.GetVariableNames()){
            Console.WriteLine($"Variable: {varName}, Value: {scope.GetVariable(varName)}");
        }
    }
}

enter image description here

why i am getting error as

future feature is not defined:annotations

1

2 Answers 2

0

As 001 commented, you can only import annotations from __future__ in Python 3.7 and IronPython currently only implements Python 3.4 (as stated here: https://ironpython.net/) and Pandas officially supports only 3.9, 3.10 and 3.11. (also stated here: https://pandas.pydata.org/docs/getting_started/install.html).

You could use an older Pandas version from https://pypi.org/project/pandas/#history but I don't know if there are security risks and if the documentation exists.

1
  • Do you know any other way to do the same , Commented Dec 7, 2023 at 8:35
0

You cannot use Pandas with IronPython. Pandas is like Numpy, Scipy, Matplotlib etc. relying on C libraries which go not well with C#.

See here or here.

Try going for Pythonnet instead.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.