How can I Integrate Python version 3 with .Net










1














I am Integrating Python script to .Net and I am using IronPython package that's available for .Net developers in Visual Studio. My Python code contains packages like face_recognition, glob, opencv. I am getting an error when I'am running this python script although the simple Python is running in PyCharm. Can anyone know what I am doing wrong? Please give me the answer that I should do.



These packages I am using and later I am using it by calling them:



import face_recognition
import cv2
import glob

video_capture = cv2.VideoCapture(0)

all_images = glob.glob('images/*.jpg')


And this is my Code which is in Visual Studio: (Making a Console App)



 var py = Python.CreateEngine();

py.ExecuteFile("C:\Users\Hp\PycharmProjects\final_face\example.py");
Console.ReadLine();


And the error I am getting by the Visual Studio is:



Exception thrown: 'Microsoft.Scripting.SyntaxErrorException' in Microsoft.Scripting.dll

The program '[23408] PythonDotNet.exe' has exited with code 0 (0x0).









share|improve this question























  • are you using the same Python version for both the native (CPython) and IronPython interpreters? There are many differences between v2 and v3.
    – Alexander Pope
    Nov 10 '18 at 16:17










  • No, IronPython latest version is 2.7.9 and CPython is 3.6.6.
    – M A K
    Nov 19 '18 at 12:23










  • Then you found the problem, IronPython 3 is not ready for production, see github.com/IronLanguages/ironpython3
    – Alexander Pope
    Nov 19 '18 at 22:27










  • Instead of using IronPython you can execute the Python script in a command line and parse the output, see if this helps: stackoverflow.com/questions/206323/…
    – Alexander Pope
    Nov 19 '18 at 22:34










  • @AlexanderPope Thanks man your suggested link has my answer. I am answering to my question below.
    – M A K
    Nov 20 '18 at 8:17















1














I am Integrating Python script to .Net and I am using IronPython package that's available for .Net developers in Visual Studio. My Python code contains packages like face_recognition, glob, opencv. I am getting an error when I'am running this python script although the simple Python is running in PyCharm. Can anyone know what I am doing wrong? Please give me the answer that I should do.



These packages I am using and later I am using it by calling them:



import face_recognition
import cv2
import glob

video_capture = cv2.VideoCapture(0)

all_images = glob.glob('images/*.jpg')


And this is my Code which is in Visual Studio: (Making a Console App)



 var py = Python.CreateEngine();

py.ExecuteFile("C:\Users\Hp\PycharmProjects\final_face\example.py");
Console.ReadLine();


And the error I am getting by the Visual Studio is:



Exception thrown: 'Microsoft.Scripting.SyntaxErrorException' in Microsoft.Scripting.dll

The program '[23408] PythonDotNet.exe' has exited with code 0 (0x0).









share|improve this question























  • are you using the same Python version for both the native (CPython) and IronPython interpreters? There are many differences between v2 and v3.
    – Alexander Pope
    Nov 10 '18 at 16:17










  • No, IronPython latest version is 2.7.9 and CPython is 3.6.6.
    – M A K
    Nov 19 '18 at 12:23










  • Then you found the problem, IronPython 3 is not ready for production, see github.com/IronLanguages/ironpython3
    – Alexander Pope
    Nov 19 '18 at 22:27










  • Instead of using IronPython you can execute the Python script in a command line and parse the output, see if this helps: stackoverflow.com/questions/206323/…
    – Alexander Pope
    Nov 19 '18 at 22:34










  • @AlexanderPope Thanks man your suggested link has my answer. I am answering to my question below.
    – M A K
    Nov 20 '18 at 8:17













1












1








1







I am Integrating Python script to .Net and I am using IronPython package that's available for .Net developers in Visual Studio. My Python code contains packages like face_recognition, glob, opencv. I am getting an error when I'am running this python script although the simple Python is running in PyCharm. Can anyone know what I am doing wrong? Please give me the answer that I should do.



These packages I am using and later I am using it by calling them:



import face_recognition
import cv2
import glob

video_capture = cv2.VideoCapture(0)

all_images = glob.glob('images/*.jpg')


And this is my Code which is in Visual Studio: (Making a Console App)



 var py = Python.CreateEngine();

py.ExecuteFile("C:\Users\Hp\PycharmProjects\final_face\example.py");
Console.ReadLine();


And the error I am getting by the Visual Studio is:



Exception thrown: 'Microsoft.Scripting.SyntaxErrorException' in Microsoft.Scripting.dll

The program '[23408] PythonDotNet.exe' has exited with code 0 (0x0).









share|improve this question















I am Integrating Python script to .Net and I am using IronPython package that's available for .Net developers in Visual Studio. My Python code contains packages like face_recognition, glob, opencv. I am getting an error when I'am running this python script although the simple Python is running in PyCharm. Can anyone know what I am doing wrong? Please give me the answer that I should do.



These packages I am using and later I am using it by calling them:



import face_recognition
import cv2
import glob

video_capture = cv2.VideoCapture(0)

all_images = glob.glob('images/*.jpg')


And this is my Code which is in Visual Studio: (Making a Console App)



 var py = Python.CreateEngine();

py.ExecuteFile("C:\Users\Hp\PycharmProjects\final_face\example.py");
Console.ReadLine();


And the error I am getting by the Visual Studio is:



Exception thrown: 'Microsoft.Scripting.SyntaxErrorException' in Microsoft.Scripting.dll

The program '[23408] PythonDotNet.exe' has exited with code 0 (0x0).






c# python .net opencv face-recognition






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 13 '18 at 11:36

























asked Nov 10 '18 at 12:18









M A K

255




255











  • are you using the same Python version for both the native (CPython) and IronPython interpreters? There are many differences between v2 and v3.
    – Alexander Pope
    Nov 10 '18 at 16:17










  • No, IronPython latest version is 2.7.9 and CPython is 3.6.6.
    – M A K
    Nov 19 '18 at 12:23










  • Then you found the problem, IronPython 3 is not ready for production, see github.com/IronLanguages/ironpython3
    – Alexander Pope
    Nov 19 '18 at 22:27










  • Instead of using IronPython you can execute the Python script in a command line and parse the output, see if this helps: stackoverflow.com/questions/206323/…
    – Alexander Pope
    Nov 19 '18 at 22:34










  • @AlexanderPope Thanks man your suggested link has my answer. I am answering to my question below.
    – M A K
    Nov 20 '18 at 8:17
















  • are you using the same Python version for both the native (CPython) and IronPython interpreters? There are many differences between v2 and v3.
    – Alexander Pope
    Nov 10 '18 at 16:17










  • No, IronPython latest version is 2.7.9 and CPython is 3.6.6.
    – M A K
    Nov 19 '18 at 12:23










  • Then you found the problem, IronPython 3 is not ready for production, see github.com/IronLanguages/ironpython3
    – Alexander Pope
    Nov 19 '18 at 22:27










  • Instead of using IronPython you can execute the Python script in a command line and parse the output, see if this helps: stackoverflow.com/questions/206323/…
    – Alexander Pope
    Nov 19 '18 at 22:34










  • @AlexanderPope Thanks man your suggested link has my answer. I am answering to my question below.
    – M A K
    Nov 20 '18 at 8:17















are you using the same Python version for both the native (CPython) and IronPython interpreters? There are many differences between v2 and v3.
– Alexander Pope
Nov 10 '18 at 16:17




are you using the same Python version for both the native (CPython) and IronPython interpreters? There are many differences between v2 and v3.
– Alexander Pope
Nov 10 '18 at 16:17












No, IronPython latest version is 2.7.9 and CPython is 3.6.6.
– M A K
Nov 19 '18 at 12:23




No, IronPython latest version is 2.7.9 and CPython is 3.6.6.
– M A K
Nov 19 '18 at 12:23












Then you found the problem, IronPython 3 is not ready for production, see github.com/IronLanguages/ironpython3
– Alexander Pope
Nov 19 '18 at 22:27




Then you found the problem, IronPython 3 is not ready for production, see github.com/IronLanguages/ironpython3
– Alexander Pope
Nov 19 '18 at 22:27












Instead of using IronPython you can execute the Python script in a command line and parse the output, see if this helps: stackoverflow.com/questions/206323/…
– Alexander Pope
Nov 19 '18 at 22:34




Instead of using IronPython you can execute the Python script in a command line and parse the output, see if this helps: stackoverflow.com/questions/206323/…
– Alexander Pope
Nov 19 '18 at 22:34












@AlexanderPope Thanks man your suggested link has my answer. I am answering to my question below.
– M A K
Nov 20 '18 at 8:17




@AlexanderPope Thanks man your suggested link has my answer. I am answering to my question below.
– M A K
Nov 20 '18 at 8:17












2 Answers
2






active

oldest

votes


















1














You are getting an error because that function is not what you want.



Create a new Console App Project called RunPython.csproj. In the main sub, write:



static void Main(string args)

var py = Python.CreateRuntime();
py.ExecuteFile();



After that, you can build your project to generate an ".exe" file. In Console or a shell, write:



RunPython.exe "C:UsersHpPycharmProjectsfinal_faceexample.py"


You can visit this site for more examples.






share|improve this answer






















  • No it is not working man. It throwing an error and showing build failed in the Error List.
    – M A K
    Nov 19 '18 at 12:19


















0














IronPython 3 is not ready for production so Instead of using IronPython you can execute the Python script in a command line and parse the output:



 class Program

static void Main(string args)

Program p = new Program();
p.butPython();


public void butPython()

var hello = "Calling Python...";

Tuple<String, String> python = GoPython(@"C:UsersHPPycharmProjectsfinal_facefinal.py");
hello = python.Item1; // Show result.
Console.WriteLine(hello);
Console.ReadLine();


public Tuple<String, String> GoPython(string pythonFile, string moreArgs = "")

ProcessStartInfo PSI = new ProcessStartInfo();
PSI.FileName = "py.exe";
PSI.Arguments = string.Format(""0" 1", pythonFile, moreArgs);
PSI.CreateNoWindow = true;
PSI.UseShellExecute = false;
PSI.RedirectStandardError = true;
PSI.RedirectStandardOutput = true;
using (Process process = Process.Start(PSI))
using (StreamReader reader = process.StandardOutput)

string stderr = process.StandardError.ReadToEnd(); // Error(s)!!
string result = reader.ReadToEnd(); // What we want.
return new Tuple<String, String>(result, stderr);








share|improve this answer




















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53238878%2fhow-can-i-integrate-python-version-3-with-net%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    You are getting an error because that function is not what you want.



    Create a new Console App Project called RunPython.csproj. In the main sub, write:



    static void Main(string args)

    var py = Python.CreateRuntime();
    py.ExecuteFile();



    After that, you can build your project to generate an ".exe" file. In Console or a shell, write:



    RunPython.exe "C:UsersHpPycharmProjectsfinal_faceexample.py"


    You can visit this site for more examples.






    share|improve this answer






















    • No it is not working man. It throwing an error and showing build failed in the Error List.
      – M A K
      Nov 19 '18 at 12:19















    1














    You are getting an error because that function is not what you want.



    Create a new Console App Project called RunPython.csproj. In the main sub, write:



    static void Main(string args)

    var py = Python.CreateRuntime();
    py.ExecuteFile();



    After that, you can build your project to generate an ".exe" file. In Console or a shell, write:



    RunPython.exe "C:UsersHpPycharmProjectsfinal_faceexample.py"


    You can visit this site for more examples.






    share|improve this answer






















    • No it is not working man. It throwing an error and showing build failed in the Error List.
      – M A K
      Nov 19 '18 at 12:19













    1












    1








    1






    You are getting an error because that function is not what you want.



    Create a new Console App Project called RunPython.csproj. In the main sub, write:



    static void Main(string args)

    var py = Python.CreateRuntime();
    py.ExecuteFile();



    After that, you can build your project to generate an ".exe" file. In Console or a shell, write:



    RunPython.exe "C:UsersHpPycharmProjectsfinal_faceexample.py"


    You can visit this site for more examples.






    share|improve this answer














    You are getting an error because that function is not what you want.



    Create a new Console App Project called RunPython.csproj. In the main sub, write:



    static void Main(string args)

    var py = Python.CreateRuntime();
    py.ExecuteFile();



    After that, you can build your project to generate an ".exe" file. In Console or a shell, write:



    RunPython.exe "C:UsersHpPycharmProjectsfinal_faceexample.py"


    You can visit this site for more examples.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 10 '18 at 22:02









    rm-

    4,25622451




    4,25622451










    answered Nov 10 '18 at 17:49









    D. Hurtado

    816




    816











    • No it is not working man. It throwing an error and showing build failed in the Error List.
      – M A K
      Nov 19 '18 at 12:19
















    • No it is not working man. It throwing an error and showing build failed in the Error List.
      – M A K
      Nov 19 '18 at 12:19















    No it is not working man. It throwing an error and showing build failed in the Error List.
    – M A K
    Nov 19 '18 at 12:19




    No it is not working man. It throwing an error and showing build failed in the Error List.
    – M A K
    Nov 19 '18 at 12:19













    0














    IronPython 3 is not ready for production so Instead of using IronPython you can execute the Python script in a command line and parse the output:



     class Program

    static void Main(string args)

    Program p = new Program();
    p.butPython();


    public void butPython()

    var hello = "Calling Python...";

    Tuple<String, String> python = GoPython(@"C:UsersHPPycharmProjectsfinal_facefinal.py");
    hello = python.Item1; // Show result.
    Console.WriteLine(hello);
    Console.ReadLine();


    public Tuple<String, String> GoPython(string pythonFile, string moreArgs = "")

    ProcessStartInfo PSI = new ProcessStartInfo();
    PSI.FileName = "py.exe";
    PSI.Arguments = string.Format(""0" 1", pythonFile, moreArgs);
    PSI.CreateNoWindow = true;
    PSI.UseShellExecute = false;
    PSI.RedirectStandardError = true;
    PSI.RedirectStandardOutput = true;
    using (Process process = Process.Start(PSI))
    using (StreamReader reader = process.StandardOutput)

    string stderr = process.StandardError.ReadToEnd(); // Error(s)!!
    string result = reader.ReadToEnd(); // What we want.
    return new Tuple<String, String>(result, stderr);








    share|improve this answer

























      0














      IronPython 3 is not ready for production so Instead of using IronPython you can execute the Python script in a command line and parse the output:



       class Program

      static void Main(string args)

      Program p = new Program();
      p.butPython();


      public void butPython()

      var hello = "Calling Python...";

      Tuple<String, String> python = GoPython(@"C:UsersHPPycharmProjectsfinal_facefinal.py");
      hello = python.Item1; // Show result.
      Console.WriteLine(hello);
      Console.ReadLine();


      public Tuple<String, String> GoPython(string pythonFile, string moreArgs = "")

      ProcessStartInfo PSI = new ProcessStartInfo();
      PSI.FileName = "py.exe";
      PSI.Arguments = string.Format(""0" 1", pythonFile, moreArgs);
      PSI.CreateNoWindow = true;
      PSI.UseShellExecute = false;
      PSI.RedirectStandardError = true;
      PSI.RedirectStandardOutput = true;
      using (Process process = Process.Start(PSI))
      using (StreamReader reader = process.StandardOutput)

      string stderr = process.StandardError.ReadToEnd(); // Error(s)!!
      string result = reader.ReadToEnd(); // What we want.
      return new Tuple<String, String>(result, stderr);








      share|improve this answer























        0












        0








        0






        IronPython 3 is not ready for production so Instead of using IronPython you can execute the Python script in a command line and parse the output:



         class Program

        static void Main(string args)

        Program p = new Program();
        p.butPython();


        public void butPython()

        var hello = "Calling Python...";

        Tuple<String, String> python = GoPython(@"C:UsersHPPycharmProjectsfinal_facefinal.py");
        hello = python.Item1; // Show result.
        Console.WriteLine(hello);
        Console.ReadLine();


        public Tuple<String, String> GoPython(string pythonFile, string moreArgs = "")

        ProcessStartInfo PSI = new ProcessStartInfo();
        PSI.FileName = "py.exe";
        PSI.Arguments = string.Format(""0" 1", pythonFile, moreArgs);
        PSI.CreateNoWindow = true;
        PSI.UseShellExecute = false;
        PSI.RedirectStandardError = true;
        PSI.RedirectStandardOutput = true;
        using (Process process = Process.Start(PSI))
        using (StreamReader reader = process.StandardOutput)

        string stderr = process.StandardError.ReadToEnd(); // Error(s)!!
        string result = reader.ReadToEnd(); // What we want.
        return new Tuple<String, String>(result, stderr);








        share|improve this answer












        IronPython 3 is not ready for production so Instead of using IronPython you can execute the Python script in a command line and parse the output:



         class Program

        static void Main(string args)

        Program p = new Program();
        p.butPython();


        public void butPython()

        var hello = "Calling Python...";

        Tuple<String, String> python = GoPython(@"C:UsersHPPycharmProjectsfinal_facefinal.py");
        hello = python.Item1; // Show result.
        Console.WriteLine(hello);
        Console.ReadLine();


        public Tuple<String, String> GoPython(string pythonFile, string moreArgs = "")

        ProcessStartInfo PSI = new ProcessStartInfo();
        PSI.FileName = "py.exe";
        PSI.Arguments = string.Format(""0" 1", pythonFile, moreArgs);
        PSI.CreateNoWindow = true;
        PSI.UseShellExecute = false;
        PSI.RedirectStandardError = true;
        PSI.RedirectStandardOutput = true;
        using (Process process = Process.Start(PSI))
        using (StreamReader reader = process.StandardOutput)

        string stderr = process.StandardError.ReadToEnd(); // Error(s)!!
        string result = reader.ReadToEnd(); // What we want.
        return new Tuple<String, String>(result, stderr);









        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 20 '18 at 8:22









        M A K

        255




        255



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53238878%2fhow-can-i-integrate-python-version-3-with-net%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

            Crossroads (UK TV series)

            ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế