Skip to content

Tool for cross-platform interacting C# and Python system interpreters

License

Notifications You must be signed in to change notification settings

flexxxxer/PythonInterop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PythonInterop

Tool for cross-platform interacting C# and Python system interpreters

Gettiong started

This library is made on .net standard 2.0, respectively, there is compatibility with .net framework 4.6.2+ and .net core 2.0+

Features:

  • working on Windows, macOS and Linux
  • lazy getting all system interpreters with their versions and paths
  • running a python script using the specified interpreter

Usage

Getting all system interpreters
IEnumerable<PythonInterpreter> interpreters = PythonEngine.PythonInterpreters;
Getting actual interpreter
var actualInterpreter = PythonEngine.PythonInterpreters
                        .OrderByDescending(i => i.Version)
                        .First();
Getting the first interpreter with version 3 above
var interpreter = PythonEngine.PythonInterpreters
                  .First(i => string.CompareOrdinal(i.Version, "3.0.0") > 1);

Getting an interpreter related only to the second version (i.e. between 2.0.0 and 2.99.99)

var interpreter = PythonEngine.PythonInterpreters
                  .First(i => string.CompareOrdinal(i.Version, "3.0.0") < 0 &&
                              string.CompareOrdinal(i.Version, "2.0.0") > 1);

Execute existing script with some interpreter

PythonInterpreter enigEngine = PythonEngine.PythonInterpreters.First();
PythonEngine engine = new PythonEngine(enigEngine);
ExecutionResult result = engine.Execute("path-to-script.py", "argValue1", "argValue2", "argValueN");

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT

About

Tool for cross-platform interacting C# and Python system interpreters

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages