0

I have written a python file which I want to use in a C# application ,but I Don't want having to install python and dependencies every time I run it in a new computer, so I want to compile it to an .exe, pass the parameters to it, and get the output.

my code file looks something like this:

import ...
import ...

def function(parameter):
 ....

how do I pass the parameter to the function, and recieve the function's output?

ShkMo
  • 5
  • 3
  • 2
    If you write Python code, you need to use Python. As an alternative, if you want to mix Python and C# code, you can use IronPython for .NET. – vz0 Apr 06 '18 at 11:53
  • @vz0 But my script uses alot of librarys which are not supported by IronPython (Scikit-learn,pandas,Numpy) – ShkMo Apr 06 '18 at 11:57

1 Answers1

0

From the Python on Windows FAQ:
How do I make an executable from a Python script?

See http://cx-freeze.sourceforge.net/ for a distutils extension that allows you to create console and GUI executables from Python code. py2exe, the most popular extension for building Python 2.x-based executables, does not yet support Python 3 but a version that does is in development.

Also see

And on SO:

handle
  • 5,859
  • 3
  • 54
  • 82
  • 1
    A link to a solution is welcome, but please ensure your answer is useful without it: [add context around the link](//meta.stackexchange.com/a/8259) so your fellow users will have some idea what it is and why it’s there, then quote the most relevant part of the page you're linking to in case the target page is unavailable. [Answers that are little more than a link may be deleted.](//stackoverflow.com/help/deleted-answers) – Zoe Apr 06 '18 at 12:18
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/low-quality-posts/19352418) – Jeru Luke Apr 06 '18 at 13:56
  • @JeruLuke That was already pointed out 10 seconds after my post (an hour ago), and I've since added information - is that not visible in Review? – handle Apr 06 '18 at 14:17
  • @handle Haven't tried it yet but it seems like a very viable solution, thank you for the help and I'll update the question if it works out – ShkMo Apr 06 '18 at 18:41
  • @ShkMo There is also the [Embedded Distribution](https://docs.python.org/3.6/using/windows.html#embedded-distribution) that does not require installation, but installing additional library packages can be a bit trick. While it's not a single exe, it's a manageable number of (packed) files, that you could probably minimize for your needs to cut down on total size. – handle Apr 06 '18 at 18:50