-
-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathProgram.cs
More file actions
48 lines (38 loc) · 1.93 KB
/
Copy pathProgram.cs
File metadata and controls
48 lines (38 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System;
using System.IO;
using System.Threading.Tasks;
using Python.Runtime;
namespace Python.Deployment.EmbeddedResource
{
class Program
{
static async Task Main(string[] args)
{
// ================================================
// This example demonstrates how to embed a Python distribution (v3.8.5) and install it locally
// ================================================
// set the installation source to be the embedded python zip from our resources
Python.Deployment.Installer.Source = new Deployment.Installer.EmbeddedResourceInstallationSource()
{
Assembly = typeof(Program).Assembly,
ResourceName = "python-3.8.5-embed-amd64.zip",
};
// install in local directory. if you don't set it will install in local app data of your user account
Python.Deployment.Installer.InstallPath = Path.GetFullPath(".");
// see what the installer is doing
Python.Deployment.Installer.LogMessage += Console.WriteLine;
// install from the given source
await Python.Deployment.Installer.SetupPython();
Runtime.Runtime.PythonDLL = "python38.dll"; // set the python dll to use, this is the one we just installed
// ok, now use pythonnet from that installation
PythonEngine.Initialize();
// call Python's sys.version to prove we are executing the right version
dynamic sys=Py.Import("sys");
Console.WriteLine("### Python version:\n\t" + sys.version);
// call os.getcwd() to prove we are executing the locally installed embedded python distribution
dynamic os = Py.Import("os");
Console.WriteLine("### Current working directory:\n\t" + os.getcwd());
Console.WriteLine("### PythonPath:\n\t" + PythonEngine.PythonPath);
}
}
}