IronPython Microsoft.Scripting.SyntaxErrorException: Could not find file

Hossain, Shakir 21 Reputation points
2022-03-07T19:39:22.933+00:00

I am pretty new in .net applications. I am trying to create a desktop application which will run python scripts in c#. I am using IronPython but it cannot find the python file it needs to be executed. The file does exist in the directory and the script runs fine externally. Any help to find a work around will be great help.180689-ironpython.jpg

Developer technologies C#
0 comments No comments
{count} votes

Accepted answer
  1. Jack J Jun 25,296 Reputation points
    2022-03-08T05:39:57.417+00:00

    @Hossain, Shakir , Welcome to Microsoft Q&A, based on my test, I find that it indeed is the path problem and I can get the correct result from the absolute path. If the absolute path is not working for you, have you considered use relative path?If considered, you can copy the python file into your current project bin->debug folder.

    Then you could use the following code to call the python file.

     var engine=Python.CreateEngine();  
      engine.ExecuteFile("test1.py");  
    

    Best Regards,
    Jack


    If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.