'C# with Iron python Error: Microsoft.Scripting.SyntaxErrorException: 'unexpected token 'from''

I'm trying to execute a python file in c#. But I'm getting an error when I'm trying to execute the python file. The error is Microsoft.Scripting.SyntaxErrorException: 'unexpected token 'from''. I am using ironpython3.4 to try to execute the python file. My c# code is to execute the python file is:

        private static void doPython()
        {
            ScriptEngine engine = Python.CreateEngine();
            List<string> pathes = engine.GetSearchPaths().ToList();
            pathes.AddRange(new[]
            {
            @"C:\Users\Erik\AppData\Local\Programs\Python\Python310\Lib", @"C:\Users\Erik\AppData\Local\Programs\Python\Python37-32\Lib\site-packages"
            });
            engine.SetSearchPaths(pathes);
            engine.ExecuteFile(@"C:/Users/Erik/Desktop/Robotstift2/Plaatje.py");

        }

In my python file, I import cv2 and numpy as np. This is the code what I want to execute:

import cv2
import numpy as np
imgage = cv2.imread('C:/Users/Erik/Desktop/RobotStift/donald4.jpg')
gray = cv2.cvtColor(imgage, cv2.COLOR_BGR2GRAY)
edges = cv2.Canny(gray,67,150,apertureSize = 3)
cv2.imshow('edges', edges)
lines = cv2.HoughLinesP(edges,1,np.pi/180,100,minLineLength=10,maxLineGap=1)
for line in lines:
    x1,y1,x2,y2 = line[0]
    cv2.line(imgage,(x1,y1),(x2,y2),(25,200,25),2)
white = ~edges
pic = cv2.resize(white,(10,10))
cv2.imwrite("hello2.png",white)
cv2.imwrite("hello3.png",pic)
cv2.imshow('white', white)
cv2.imshow('pic', pic)
k = cv2.waitKey(0)
cv2.destroyAllWindows()


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source